From dc5528c558e81e318496e596e5ceb13a71bd6fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=B9=BF?= Date: Tue, 24 Jun 2025 12:56:45 +0800 Subject: [PATCH] =?UTF-8?q?"feat(config):=20=E6=94=AF=E6=8C=81JSON?= =?UTF-8?q?=E6=B5=81=E5=BC=8F=E8=A7=A3=E6=9E=90=E4=BB=A5=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=A4=9A=E6=9C=8D=E5=8A=A1=E5=99=A8=E9=85=8D=E7=BD=AE"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gohttp.go | 24 ++++++++++++++++++------ include/www.a.com.json | 13 +++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/gohttp.go b/gohttp.go index c893486..1f97694 100644 --- a/gohttp.go +++ b/gohttp.go @@ -5,6 +5,7 @@ import ( "net/http" "os" "path/filepath" + "strings" "git.pyer.club/kingecg/gohttpd/admin" "git.pyer.club/kingecg/gohttpd/model" @@ -113,16 +114,27 @@ func LoadConfig() { configs, err := filepath.Glob(model.Config.IncludDir + "/*.json") if err == nil { for _, config := range configs { - server := model.HttpServerConfig{} + // read config content and unmarshal content, err := os.ReadFile(config) if err == nil { - err = json.Unmarshal(content, &server) - if err == nil { - server.ConfPath = config - normalizeServer(&server) - model.Config.Servers = append(model.Config.Servers, &server) + decoder := json.NewDecoder(strings.NewReader(string(content))) + for decoder.More() { + server := model.HttpServerConfig{} + err = decoder.Decode(&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) + + // } } } } diff --git a/include/www.a.com.json b/include/www.a.com.json index a093e9d..1117398 100644 --- a/include/www.a.com.json +++ b/include/www.a.com.json @@ -10,4 +10,17 @@ "default": "index.html" } ] +} +{ + "name": "ahttp", + "server": ["www.a.com"], + "port": 8089, + "enable_ssl":false, + "paths": [ + { + "path": "/", + "root": "./example", + "default": "index.html" + } + ] } \ No newline at end of file