expose PATCH /config
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
package v01
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"mayhem-party/src/device/input/wrap"
|
||||
"net/http"
|
||||
"os"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func (v01 *V01) listen() {
|
||||
@@ -55,6 +59,8 @@ func (v01 *V01) serveHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
v01.getUserFeedback(w, r)
|
||||
case "/broadcast":
|
||||
v01.putBroadcast(w, r)
|
||||
case "/config":
|
||||
v01.patchConfig(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +79,21 @@ func (v01 *V01) putBroadcast(w http.ResponseWriter, r *http.Request) {
|
||||
v01.cfg.Users["broadcast"] = v
|
||||
}
|
||||
|
||||
func (v01 *V01) patchConfig(w http.ResponseWriter, r *http.Request) {
|
||||
b, _ := io.ReadAll(r.Body)
|
||||
var v []interface{}
|
||||
if err := json.Unmarshal(b, &v); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
v01.cfg = v01.cfg.WithPatch(v)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (v01 *V01) globalQueries(r *http.Request) {
|
||||
v01.globalQuerySay(r)
|
||||
v01.globalQueryRefresh(r)
|
||||
|
||||
Reference in New Issue
Block a user