2026-02-19 11:29:44 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
|
|
import "context"
|
|
|
|
|
|
|
|
|
|
type userKeyType struct{}
|
2026-02-20 23:22:10 +00:00
|
|
|
type siteKeyType struct{}
|
2026-02-19 11:29:44 +00:00
|
|
|
|
|
|
|
|
var userKey = userKeyType{}
|
2026-03-02 09:48:41 +00:00
|
|
|
var siteKey = siteKeyType{}
|
2026-02-19 11:29:44 +00:00
|
|
|
|
|
|
|
|
func WithUser(ctx context.Context, user User) context.Context {
|
|
|
|
|
return context.WithValue(ctx, userKey, user)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetUser(ctx context.Context) (User, bool) {
|
|
|
|
|
user, ok := ctx.Value(userKey).(User)
|
|
|
|
|
return user, ok
|
|
|
|
|
}
|
2026-02-20 23:22:10 +00:00
|
|
|
|
|
|
|
|
func WithSite(ctx context.Context, site Site) context.Context {
|
|
|
|
|
return context.WithValue(ctx, siteKey, site)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetSite(ctx context.Context) (Site, bool) {
|
|
|
|
|
site, ok := ctx.Value(siteKey).(Site)
|
|
|
|
|
return site, ok
|
|
|
|
|
}
|