init
This commit is contained in:
commit
b15b95781c
108 changed files with 14802 additions and 0 deletions
32
internal/apikeys/context.go
Normal file
32
internal/apikeys/context.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package apikeys
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"update_server/internal/db"
|
||||
)
|
||||
|
||||
type contextKey string
|
||||
|
||||
const requestContextKey contextKey = "api-key"
|
||||
|
||||
type AuthState struct {
|
||||
APIKey db.APIKey
|
||||
}
|
||||
|
||||
func NewContext(ctx context.Context, state *AuthState) context.Context {
|
||||
if state == nil {
|
||||
return ctx
|
||||
}
|
||||
|
||||
return context.WithValue(ctx, requestContextKey, *state)
|
||||
}
|
||||
|
||||
func FromContext(ctx context.Context) (*AuthState, bool) {
|
||||
state, ok := ctx.Value(requestContextKey).(AuthState)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
return &state, true
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue