From 60d391b7a48bf41c6d54311424b39b65912e1bfb Mon Sep 17 00:00:00 2001 From: bel Date: Mon, 27 Mar 2023 21:05:38 -0600 Subject: [PATCH] flush config to disk every http --- src/device/input/parse/v01/server.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/device/input/parse/v01/server.go b/src/device/input/parse/v01/server.go index 4c70f77..9a825e4 100644 --- a/src/device/input/parse/v01/server.go +++ b/src/device/input/parse/v01/server.go @@ -40,6 +40,7 @@ func (v01 *V01) _listen() { defer mutex.Unlock() } v01.ServeHTTP(w, r) + v01.stashConfig() // TODO }), } go func() { @@ -113,11 +114,20 @@ func (v01 *V01) servePatchConfig(w http.ResponseWriter, r *http.Request) { return } v01.cfg = v01.cfg.WithPatch(v) + if err := v01.stashConfig(); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } +} + +func (v01 *V01) stashConfig() error { if b, err := yaml.Marshal(v01.cfg); err == nil && FlagParseV01Config != "" { if err := os.WriteFile(FlagParseV01Config, b, os.ModePerm); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + return err } + } else if err != nil { + return err } + return nil } func (v01 *V01) serveGlobalQueries(r *http.Request) { @@ -167,6 +177,7 @@ func (v01 *V01) serveGM(w http.ResponseWriter, r *http.Request) { } default: http.NotFound(w, r) + return } }