forked from grafana.jool/grafana-jool
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.3 KiB
54 lines
1.3 KiB
package livecontext
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
)
|
|
|
|
type signedUserContextKeyType int
|
|
|
|
var signedUserContextKey signedUserContextKeyType
|
|
|
|
func SetContextSignedUser(ctx context.Context, user *models.SignedInUser) context.Context {
|
|
ctx = context.WithValue(ctx, signedUserContextKey, user)
|
|
return ctx
|
|
}
|
|
|
|
func GetContextSignedUser(ctx context.Context) (*models.SignedInUser, bool) {
|
|
if val := ctx.Value(signedUserContextKey); val != nil {
|
|
user, ok := val.(*models.SignedInUser)
|
|
return user, ok
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
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
|
|
}
|
|
|