diff --git a/hub/route/configs.go b/hub/route/configs.go index 66d6cb433..8954f93e4 100644 --- a/hub/route/configs.go +++ b/hub/route/configs.go @@ -5,8 +5,8 @@ import ( "github.com/Dreamacro/clash/hub/executor" "github.com/Dreamacro/clash/log" - T "github.com/Dreamacro/clash/tunnel" P "github.com/Dreamacro/clash/proxy" + T "github.com/Dreamacro/clash/tunnel" "github.com/go-chi/chi" "github.com/go-chi/render" @@ -15,6 +15,7 @@ import ( func configRouter() http.Handler { r := chi.NewRouter() r.Get("/", getConfigs) + r.Patch("/", patchConfigs) return r } @@ -32,7 +33,7 @@ func getConfigs(w http.ResponseWriter, r *http.Request) { render.Respond(w, r, general) } -func pointerOrDefault (p *int, def int) int { +func pointerOrDefault(p *int, def int) int { if p != nil { return *p } @@ -40,7 +41,7 @@ func pointerOrDefault (p *int, def int) int { return def } -func updateConfigs(w http.ResponseWriter, r *http.Request) { +func patchConfigs(w http.ResponseWriter, r *http.Request) { general := &configSchema{} if err := render.DecodeJSON(r.Body, general); err != nil { w.WriteHeader(http.StatusBadRequest) @@ -51,7 +52,7 @@ func updateConfigs(w http.ResponseWriter, r *http.Request) { if general.AllowLan != nil { P.SetAllowLan(*general.AllowLan) } - + ports := P.GetPorts() P.ReCreateHTTP(pointerOrDefault(general.Port, ports.Port)) P.ReCreateSocks(pointerOrDefault(general.SocksPort, ports.SocksPort)) diff --git a/log/level.go b/log/level.go index 4e28e7143..2bdbad4d9 100644 --- a/log/level.go +++ b/log/level.go @@ -46,7 +46,7 @@ func (l LogLevel) MarshalYAML() ([]byte, error) { // UnmarshalJSON unserialize Mode with json func (l *LogLevel) UnmarshalJSON(data []byte) error { var tp string - json.Unmarshal(data, tp) + json.Unmarshal(data, &tp) level, exist := LogLevelMapping[tp] if !exist { return errors.New("invalid mode") diff --git a/tunnel/mode.go b/tunnel/mode.go index b367ed3ad..e9eb531ff 100644 --- a/tunnel/mode.go +++ b/tunnel/mode.go @@ -25,7 +25,7 @@ const ( // UnmarshalJSON unserialize Mode func (m *Mode) UnmarshalJSON(data []byte) error { var tp string - json.Unmarshal(data, tp) + json.Unmarshal(data, &tp) mode, exist := ModeMapping[tp] if !exist { return errors.New("invalid mode")