add owner handle
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
0f2d7126eb
commit
f862abe5a4
12 changed files with 274 additions and 55 deletions
|
|
@ -3,6 +3,8 @@ package handler
|
|||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"git.g3e.fr/H6N/account/internal/auth"
|
||||
)
|
||||
|
||||
func writeJSON(w http.ResponseWriter, status int, v any) {
|
||||
|
|
@ -14,3 +16,13 @@ func writeJSON(w http.ResponseWriter, status int, v any) {
|
|||
func writeError(w http.ResponseWriter, status int, msg string) {
|
||||
writeJSON(w, status, map[string]string{"error": msg})
|
||||
}
|
||||
|
||||
// requireOwner extrait l'owner du contexte ou écrit 401 et retourne false.
|
||||
func requireOwner(w http.ResponseWriter, r *http.Request) (int32, bool) {
|
||||
id, ok := auth.OwnerFromContext(r.Context())
|
||||
if !ok {
|
||||
writeError(w, http.StatusUnauthorized, "missing owner")
|
||||
return 0, false
|
||||
}
|
||||
return id, true
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue