INNER CODE UNIT · Go
WithSite
arp242/goatcounter · context.go:85
func WithSite(ctx context.Context, s *Site) context.Context {
return context.WithValue(ctx, ctxkey.Site, s)
}
// GetSite gets the current site.
func GetSite(ctx context.Context) *Site {
s, _ := ctx.Value(ctxkey.Site).(*Site)
return s
}
// MustGetSite behaves as GetSite(), panicking if this fails.
func MustGetSite(ctx context.Context) *Site {
s, ok := ctx.Value(ctxkey.Site).(*Site)
if !ok {
panic("MustGetSite: no site on context")
}
return s
}