feat: initial commit
This commit is contained in:
22
internal/http/handler/webui/auth/context.go
Normal file
22
internal/http/handler/webui/auth/context.go
Normal file
@ -0,0 +1,22 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const keyUser = "user"
|
||||
|
||||
func ContextUser(ctx context.Context) *User {
|
||||
user, ok := ctx.Value(keyUser).(*User)
|
||||
if !ok {
|
||||
panic(errors.New("no user in context"))
|
||||
}
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
func setContextUser(ctx context.Context, user *User) context.Context {
|
||||
return context.WithValue(ctx, keyUser, user)
|
||||
}
|
Reference in New Issue
Block a user