Added script management
This commit is contained in:
parent
ba7375fe15
commit
04b1325031
7 changed files with 575 additions and 4 deletions
65
webserver.go
65
webserver.go
|
|
@ -47,6 +47,9 @@ func initWebserver() (err error) {
|
|||
http.HandleFunc("/types/update/{typeID}", actionTypeUpdate)
|
||||
http.HandleFunc("/connection/update/{connID}", actionConnectionUpdate)
|
||||
http.HandleFunc("/connection/delete/{connID}", actionConnectionDelete)
|
||||
http.HandleFunc("/scripts/", actionScripts)
|
||||
http.HandleFunc("/scripts/update/{scriptID}", actionScriptUpdate)
|
||||
http.HandleFunc("/scripts/delete/{scriptID}", actionScriptDelete)
|
||||
|
||||
err = http.ListenAndServe(address, nil)
|
||||
return
|
||||
|
|
@ -551,4 +554,66 @@ func actionConnectionDelete(w http.ResponseWriter, r *http.Request) { // {{{
|
|||
w.Write(j)
|
||||
} // }}}
|
||||
|
||||
func actionScripts(w http.ResponseWriter, r *http.Request) { // {{{
|
||||
scripts, err := GetScripts()
|
||||
if err != nil {
|
||||
httpError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
out := struct {
|
||||
OK bool
|
||||
Scripts []Script
|
||||
}{
|
||||
true,
|
||||
scripts,
|
||||
}
|
||||
j, _ := json.Marshal(out)
|
||||
w.Write(j)
|
||||
} // }}}
|
||||
func actionScriptUpdate(w http.ResponseWriter, r *http.Request) { // {{{
|
||||
scriptID := 0
|
||||
scriptIDStr := r.PathValue("scriptID")
|
||||
scriptID, _ = strconv.Atoi(scriptIDStr)
|
||||
|
||||
data, _ := io.ReadAll(r.Body)
|
||||
|
||||
script, err := UpdateScript(scriptID, data)
|
||||
if err != nil {
|
||||
err = werr.Wrap(err)
|
||||
httpError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
out := struct {
|
||||
OK bool
|
||||
Script Script
|
||||
}{
|
||||
true,
|
||||
script,
|
||||
}
|
||||
j, _ := json.Marshal(out)
|
||||
w.Write(j)
|
||||
} // }}}
|
||||
func actionScriptDelete(w http.ResponseWriter, r *http.Request) { // {{{
|
||||
scriptID := 0
|
||||
scriptIDStr := r.PathValue("scriptID")
|
||||
scriptID, _ = strconv.Atoi(scriptIDStr)
|
||||
|
||||
err := DeleteScript(scriptID)
|
||||
if err != nil {
|
||||
err = werr.Wrap(err)
|
||||
httpError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
out := struct {
|
||||
OK bool
|
||||
}{
|
||||
true,
|
||||
}
|
||||
j, _ := json.Marshal(out)
|
||||
w.Write(j)
|
||||
} // }}}
|
||||
|
||||
// vim: foldmethod=marker
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue