added client calls for running servers

This commit is contained in:
2021-03-07 18:40:45 -09:00
parent 86f304e1b8
commit aa65b64867
4 changed files with 90 additions and 4 deletions

View File

@ -2,22 +2,27 @@ package server
import (
"fmt"
"net/http"
"git.binarythought.com/cdramey/alrm/api"
"net/http"
)
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/api":
g := r.URL.Query()
c := g.Get("cmd")
if err := r.ParseForm(); err != nil {
http.Error(w, fmt.Sprintf("form parse error: %s", err.Error()),
http.StatusBadRequest)
return
}
c := r.FormValue("cmd")
if c == "" {
http.Error(w, "no command given", http.StatusBadRequest)
return
}
cmd, err := api.ParseCommand([]byte(c))
if err != nil {
http.Error(w, fmt.Sprintf("error parsing command: %s", err.Error()),
http.Error(w, fmt.Sprintf("command parse error: %s", err.Error()),
http.StatusBadRequest)
return
}