Migrate to Go 1.18 (#45)

* Migrate to Go 1.18 and add linters
This commit is contained in:
Jonas Plum
2022-03-20 03:17:18 +01:00
committed by GitHub
parent 03a4806d45
commit 2bad1f5f28
88 changed files with 1430 additions and 868 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
)
@@ -22,15 +23,21 @@ func stateCookie(r *http.Request) (string, error) {
if err != nil {
return "", err
}
return stateCookie.Value, nil
}
func setClaimsCookie(w http.ResponseWriter, claims map[string]interface{}) {
b, _ := json.Marshal(claims)
func setClaimsCookie(w http.ResponseWriter, claims map[string]any) {
b, err := json.Marshal(claims)
if err != nil {
log.Println(err)
return
}
http.SetCookie(w, &http.Cookie{Name: userSessionCookie, Value: base64.StdEncoding.EncodeToString(b)})
}
func claimsCookie(r *http.Request) (map[string]interface{}, bool, error) {
func claimsCookie(r *http.Request) (map[string]any, bool, error) {
userCookie, err := r.Cookie(userSessionCookie)
if err != nil {
return nil, true, nil
@@ -41,9 +48,10 @@ func claimsCookie(r *http.Request) (map[string]interface{}, bool, error) {
return nil, false, fmt.Errorf("could not decode cookie: %w", err)
}
var claims map[string]interface{}
var claims map[string]any
if err := json.Unmarshal(b, &claims); err != nil {
return nil, false, errors.New("claims not in session")
}
return claims, false, err
}