mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
22 lines
429 B
Go
22 lines
429 B
Go
package oauthctx
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
)
|
|
|
|
type userIDContextKey struct{}
|
|
|
|
func WithUserID(ctx context.Context, userID string) context.Context {
|
|
userID = strings.TrimSpace(userID)
|
|
if userID == "" {
|
|
return ctx
|
|
}
|
|
return context.WithValue(ctx, userIDContextKey{}, userID)
|
|
}
|
|
|
|
func UserIDFromContext(ctx context.Context) string {
|
|
userID, _ := ctx.Value(userIDContextKey{}).(string)
|
|
return strings.TrimSpace(userID)
|
|
}
|