package handlers import ( "io" "log" "net/http" "strconv" "time" "gitlab.hamburg.ccc.de/ccchh/spaceapid/config" "gitlab.hamburg.ccc.de/ccchh/spaceapid/types" ) func StateOpen( authDB config.HTTPBACredentials, validCredentials []config.HTTPBACredentialID, resp *types.SpaceState, ) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { body := string(updateEndpointValidator(authDB, validCredentials, w, r)) // Parse request body newState, err := strconv.ParseBool(body) if err != nil { log.Println("Failed to parse request body from", r.RemoteAddr, "body:", body) w.WriteHeader(http.StatusBadRequest) _, _ = io.WriteString(w, "HTTP request body should either be true or false") return } // Set SpaceAPI response values resp.Open = newState resp.LastChange = time.Now().Unix() _, _ = io.WriteString(w, "Update Successful") } }