server: /whoami
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func Whoami(w http.ResponseWriter, r *http.Request) {
|
||||
slog.Debug("user: entering Whoami handler")
|
||||
user, ok := r.Context().Value(userKey{}).(*User)
|
||||
if !ok || user == nil {
|
||||
slog.Debug("user: anonymous user")
|
||||
w.Write([]byte("anonymous"))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Password string `json:"-"`
|
||||
}
|
||||
|
||||
type userKey struct{}
|
||||
|
||||
type UserPayload struct {
|
||||
*User
|
||||
}
|
||||
Reference in New Issue
Block a user