"feat(config): 支持JSON流式解析以处理多服务器配置"
This commit is contained in:
parent
eecfc51c1e
commit
dc5528c558
24
gohttp.go
24
gohttp.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.pyer.club/kingecg/gohttpd/admin"
|
"git.pyer.club/kingecg/gohttpd/admin"
|
||||||
"git.pyer.club/kingecg/gohttpd/model"
|
"git.pyer.club/kingecg/gohttpd/model"
|
||||||
|
@ -113,16 +114,27 @@ func LoadConfig() {
|
||||||
configs, err := filepath.Glob(model.Config.IncludDir + "/*.json")
|
configs, err := filepath.Glob(model.Config.IncludDir + "/*.json")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, config := range configs {
|
for _, config := range configs {
|
||||||
server := model.HttpServerConfig{}
|
|
||||||
// read config content and unmarshal
|
// read config content and unmarshal
|
||||||
content, err := os.ReadFile(config)
|
content, err := os.ReadFile(config)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = json.Unmarshal(content, &server)
|
decoder := json.NewDecoder(strings.NewReader(string(content)))
|
||||||
if err == nil {
|
for decoder.More() {
|
||||||
server.ConfPath = config
|
server := model.HttpServerConfig{}
|
||||||
normalizeServer(&server)
|
err = decoder.Decode(&server)
|
||||||
model.Config.Servers = append(model.Config.Servers, &server)
|
if err == nil {
|
||||||
|
server.ConfPath = config
|
||||||
|
normalizeServer(&server)
|
||||||
|
model.Config.Servers = append(model.Config.Servers, &server)
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// if err == nil {
|
||||||
|
// server.ConfPath = config
|
||||||
|
// normalizeServer(&server)
|
||||||
|
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,4 +10,17 @@
|
||||||
"default": "index.html"
|
"default": "index.html"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
{
|
||||||
|
"name": "ahttp",
|
||||||
|
"server": ["www.a.com"],
|
||||||
|
"port": 8089,
|
||||||
|
"enable_ssl":false,
|
||||||
|
"paths": [
|
||||||
|
{
|
||||||
|
"path": "/",
|
||||||
|
"root": "./example",
|
||||||
|
"default": "index.html"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue