diff --git a/go-socket b/go-socket index 8caf477..14cb3ed 100755 Binary files a/go-socket and b/go-socket differ diff --git a/http.go b/http.go index 4e5d96e..0fe2b1a 100644 --- a/http.go +++ b/http.go @@ -2,8 +2,8 @@ package main import ( "context" - "encoding/binary" json2 "encoding/json" + "fmt" "maps" "net/http" "slices" @@ -87,7 +87,7 @@ func getIfOwnerClientAndGroup(ctx context.Context, response *http.ResponseWriter return client, group, nil } -func HttpHandleNewUser(response http.ResponseWriter, request *http.Request) { +func HttpHandleNewClient(response http.ResponseWriter, request *http.Request) { if !isMethodAllowed(&response, request) { return } @@ -131,7 +131,7 @@ func HttpHandleNewUser(response http.ResponseWriter, request *http.Request) { return } - response.WriteHeader(http.StatusAccepted) + response.WriteHeader(http.StatusCreated) response.Write([]byte("created")) } @@ -234,11 +234,8 @@ func HttpHandeNewGroup(response http.ResponseWriter, request *http.Request) { http.Error(response, err.Error(), http.StatusInternalServerError) return } - groupIdBytes := make([]byte, 4) - binary.BigEndian.PutUint32(groupIdBytes, group.Id) - response.WriteHeader(http.StatusCreated) - response.Write(groupIdBytes) + fmt.Fprintf(response, "%d", group.Id) } func HttpHandleGroupAddClient(response http.ResponseWriter, request *http.Request) { @@ -295,11 +292,7 @@ func HttpHandleGroupAddClient(response http.ResponseWriter, request *http.Reques } response.WriteHeader(http.StatusAccepted) - _, err = response.Write([]byte("ok")) - if err != nil { - http.Error(response, "internal server error", http.StatusInternalServerError) - return - } + response.Write([]byte("ok")) } func HttpHandleGroupRemoveClient(response http.ResponseWriter, request *http.Request) { diff --git a/machine-client/index.html b/machine-client/index.html index a221b74..2518623 100644 --- a/machine-client/index.html +++ b/machine-client/index.html @@ -88,7 +88,7 @@ let ws = null; let activeForm = null; - const forms = { + var formDefs = { 'new-client': { title: 'POST /new/client — register new user', fields: [ @@ -214,10 +214,10 @@ } activeForm = name; - const def = forms[name]; + const def = formDefs[name]; // activate clicked button - const idx = Object.keys(forms).indexOf(name); + const idx = Object.keys(formDefs).indexOf(name); if (idx >= 0) { buttons[idx].classList.add('active'); if (name === 'websocket') buttons[idx].classList.add('ws'); @@ -236,7 +236,7 @@ ${f.hint ? `${f.hint}` : ''} `; } - html += `
`; + html += `
`; fieldsEl.innerHTML = html; } diff --git a/main.go b/main.go index ec0656e..23f1065 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ func main() { ctx := context.Background() DbInit(ctx) - http.HandleFunc("/new/client", withCORS(HttpHandleNewUser)) + http.HandleFunc("/new/client", withCORS(HttpHandleNewClient)) http.HandleFunc("/new/token", withCORS(HttpHandleNewToken)) http.HandleFunc("/new/group", withCORS(HttpHandeNewGroup)) http.HandleFunc("/mod/group/addclients", withCORS(HttpHandleGroupAddClient))