24 lines
397 B
Go
24 lines
397 B
Go
|
package context
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"github.com/markbates/goth"
|
||
|
"github.com/pkg/errors"
|
||
|
)
|
||
|
|
||
|
const keyUser = "user"
|
||
|
|
||
|
func User(ctx context.Context) *goth.User {
|
||
|
user, ok := ctx.Value(keyUser).(*goth.User)
|
||
|
if !ok {
|
||
|
panic(errors.New("no user in context"))
|
||
|
}
|
||
|
|
||
|
return user
|
||
|
}
|
||
|
|
||
|
func SetUser(ctx context.Context, user *goth.User) context.Context {
|
||
|
return context.WithValue(ctx, keyUser, user)
|
||
|
}
|