Session
This commit is contained in:
parent
b8a673fb0a
commit
a76c093d44
7 changed files with 192 additions and 36 deletions
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue