mirror of
https://github.com/grafana/grafana.git
synced 2025-01-26 08:16:59 -06:00
24 lines
537 B
Go
24 lines
537 B
Go
package identity
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
type ctxUserKey struct{}
|
|
|
|
// WithRequester attaches the requester to the context.
|
|
func WithRequester(ctx context.Context, usr Requester) context.Context {
|
|
return context.WithValue(ctx, ctxUserKey{}, usr)
|
|
}
|
|
|
|
// Get the Requester from context
|
|
func GetRequester(ctx context.Context) (Requester, error) {
|
|
// Set by appcontext.WithUser
|
|
u, ok := ctx.Value(ctxUserKey{}).(Requester)
|
|
if ok && u != nil {
|
|
return u, nil
|
|
}
|
|
return nil, fmt.Errorf("a Requester was not found in the context")
|
|
}
|