This commit is contained in:
Magnus Åhall 2023-06-16 07:11:27 +02:00
parent b8a673fb0a
commit a76c093d44
7 changed files with 192 additions and 36 deletions

View file

@ -3,6 +3,8 @@ package main
import (
// Standard
"encoding/json"
"errors"
"io"
"net/http"
)
@ -26,3 +28,18 @@ func responseData(w http.ResponseWriter, data interface{}) {
w.Header().Add("Content-Type", "application/json")
w.Write(resJSON)
}
func request(r *http.Request, data interface{}) (err error) {
body, _ := io.ReadAll(r.Body)
defer r.Body.Close()
err = json.Unmarshal(body, data)
return
}
func sessionUUID(r *http.Request) (string, error) {
headers := r.Header["X-Session-Id"]
if len(headers) > 0 {
return headers[0], nil
}
return "", errors.New("Invalid session")
}