2021-04-26 05:17:49 -05:00
|
|
|
package livecontext
|
2021-03-23 12:24:08 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-08-10 04:56:48 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/user"
|
2021-03-23 12:24:08 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type signedUserContextKeyType int
|
|
|
|
|
|
|
|
var signedUserContextKey signedUserContextKeyType
|
|
|
|
|
2022-08-10 04:56:48 -05:00
|
|
|
func SetContextSignedUser(ctx context.Context, user *user.SignedInUser) context.Context {
|
2021-03-23 12:24:08 -05:00
|
|
|
ctx = context.WithValue(ctx, signedUserContextKey, user)
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
2022-08-10 04:56:48 -05:00
|
|
|
func GetContextSignedUser(ctx context.Context) (*user.SignedInUser, bool) {
|
2021-03-23 12:24:08 -05:00
|
|
|
if val := ctx.Value(signedUserContextKey); val != nil {
|
2022-08-10 04:56:48 -05:00
|
|
|
user, ok := val.(*user.SignedInUser)
|
2021-03-23 12:24:08 -05:00
|
|
|
return user, ok
|
|
|
|
}
|
|
|
|
return nil, false
|
|
|
|
}
|
2021-04-19 10:48:43 -05:00
|
|
|
|
2021-05-06 14:28:14 -05:00
|
|
|
type streamIDContextKey struct{}
|
|
|
|
|
|
|
|
func SetContextStreamID(ctx context.Context, streamID string) context.Context {
|
|
|
|
ctx = context.WithValue(ctx, streamIDContextKey{}, streamID)
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetContextStreamID(ctx context.Context) (string, bool) {
|
|
|
|
if val := ctx.Value(streamIDContextKey{}); val != nil {
|
|
|
|
values, ok := val.(string)
|
|
|
|
return values, ok
|
|
|
|
}
|
|
|
|
return "", false
|
|
|
|
}
|
2021-11-15 03:43:18 -06:00
|
|
|
|
|
|
|
type channelIDContextKey struct{}
|
|
|
|
|
|
|
|
func SetContextChannelID(ctx context.Context, channelID string) context.Context {
|
|
|
|
ctx = context.WithValue(ctx, channelIDContextKey{}, channelID)
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetContextChannelID(ctx context.Context) (string, bool) {
|
|
|
|
if val := ctx.Value(channelIDContextKey{}); val != nil {
|
|
|
|
values, ok := val.(string)
|
|
|
|
return values, ok
|
|
|
|
}
|
|
|
|
return "", false
|
|
|
|
}
|