2021-04-26 05:17:49 -05:00
|
|
|
package livecontext
|
2021-03-23 12:24:08 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-04-19 10:48:43 -05:00
|
|
|
"net/url"
|
2021-03-23 12:24:08 -05:00
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
type signedUserContextKeyType int
|
|
|
|
|
|
|
|
var signedUserContextKey signedUserContextKeyType
|
|
|
|
|
2021-04-26 05:17:49 -05:00
|
|
|
func SetContextSignedUser(ctx context.Context, user *models.SignedInUser) context.Context {
|
2021-03-23 12:24:08 -05:00
|
|
|
ctx = context.WithValue(ctx, signedUserContextKey, user)
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
2021-04-26 05:17:49 -05:00
|
|
|
func GetContextSignedUser(ctx context.Context) (*models.SignedInUser, bool) {
|
2021-03-23 12:24:08 -05:00
|
|
|
if val := ctx.Value(signedUserContextKey); val != nil {
|
|
|
|
user, ok := val.(*models.SignedInUser)
|
|
|
|
return user, ok
|
|
|
|
}
|
|
|
|
return nil, false
|
|
|
|
}
|
2021-04-19 10:48:43 -05:00
|
|
|
|
|
|
|
type valuesContextKey struct{}
|
|
|
|
|
2021-04-26 05:17:49 -05:00
|
|
|
func SetContextValues(ctx context.Context, values url.Values) context.Context {
|
2021-04-19 10:48:43 -05:00
|
|
|
ctx = context.WithValue(ctx, valuesContextKey{}, values)
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
2021-04-26 05:17:49 -05:00
|
|
|
func GetContextValues(ctx context.Context) (url.Values, bool) {
|
2021-04-19 10:48:43 -05:00
|
|
|
if val := ctx.Value(valuesContextKey{}); val != nil {
|
|
|
|
values, ok := val.(url.Values)
|
|
|
|
return values, ok
|
|
|
|
}
|
|
|
|
return nil, false
|
|
|
|
}
|