parent
b6e7396ef5
commit
dc6069c8a1
28
gohttp.go
28
gohttp.go
|
@ -6,6 +6,7 @@ import (
|
|||
"os"
|
||||
|
||||
"git.pyer.club/kingecg/gohttpd/admin"
|
||||
handler "git.pyer.club/kingecg/gohttpd/hander"
|
||||
"git.pyer.club/kingecg/gohttpd/model"
|
||||
"git.pyer.club/kingecg/gohttpd/server"
|
||||
"git.pyer.club/kingecg/gologger"
|
||||
|
@ -26,8 +27,10 @@ func (g *GoHttp) Start() {
|
|||
|
||||
g.makeServer("admin", port, admin.AdminServerMux)
|
||||
|
||||
//TODO: create other server
|
||||
// }
|
||||
for _, server := range g.conf.Servers {
|
||||
sHandler := g.assembleServerMux(server.Paths)
|
||||
g.makeServer(server.ServerName, server.Port, sHandler)
|
||||
}
|
||||
|
||||
for _, listener := range server.ServerManager {
|
||||
listener.Start()
|
||||
|
@ -37,13 +40,32 @@ func (g *GoHttp) Start() {
|
|||
g.logger.Info("gohttpd start success")
|
||||
}
|
||||
|
||||
func (g *GoHttp) makeServer(name string, port int, mux *server.RestMux) {
|
||||
func (g *GoHttp) makeServer(name string, port int, mux http.Handler) {
|
||||
s := &http.Server{
|
||||
Handler: mux,
|
||||
}
|
||||
server.AddServer(name, s, port)
|
||||
}
|
||||
|
||||
func (g *GoHttp) assembleServerMux(p []model.HttpPath) http.Handler {
|
||||
s := http.NewServeMux()
|
||||
for _, httpPath := range p {
|
||||
if httpPath.Root != "" {
|
||||
fileHandler := handler.NewFileHandler(handler.FileHandler{
|
||||
Root: httpPath.Root,
|
||||
Default: httpPath.Default,
|
||||
})
|
||||
s.Handle(httpPath.Path, fileHandler)
|
||||
} else if len(httpPath.Upstreams) != 0 {
|
||||
proxyHandler := handler.NewProxyHandler(&httpPath)
|
||||
s.Handle(httpPath.Path, proxyHandler)
|
||||
} else {
|
||||
g.logger.Error("Not supportted server path type :", httpPath.Path)
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (g *GoHttp) Stop() {}
|
||||
|
||||
func (g *GoHttp) LoadConfig(configPath string) {
|
||||
|
|
Loading…
Reference in New Issue