William Petit
8eb441daee
All checks were successful
arcad/edge/pipeline/head This commit looks good
ref arcad/edge-menu#86
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type GetCookieDomainFunc func(r *http.Request) (string, error)
|
|
|
|
func defaultGetCookieDomain(r *http.Request) (string, error) {
|
|
return "", nil
|
|
}
|
|
|
|
type AnonymousUserOptions struct {
|
|
GetCookieDomain GetCookieDomainFunc
|
|
CookieDuration time.Duration
|
|
Tenant string
|
|
Entrypoint string
|
|
Role string
|
|
}
|
|
|
|
type AnonymousUserOptionFunc func(*AnonymousUserOptions)
|
|
|
|
func defaultAnonymousUserOptions() *AnonymousUserOptions {
|
|
return &AnonymousUserOptions{
|
|
GetCookieDomain: defaultGetCookieDomain,
|
|
CookieDuration: 24 * time.Hour,
|
|
Tenant: "",
|
|
Entrypoint: "",
|
|
Role: "",
|
|
}
|
|
}
|
|
|
|
func WithCookieOptions(getCookieDomain GetCookieDomainFunc, duration time.Duration) AnonymousUserOptionFunc {
|
|
return func(opts *AnonymousUserOptions) {
|
|
opts.GetCookieDomain = getCookieDomain
|
|
opts.CookieDuration = duration
|
|
}
|
|
}
|
|
|
|
func WithTenant(tenant string) AnonymousUserOptionFunc {
|
|
return func(opts *AnonymousUserOptions) {
|
|
opts.Tenant = tenant
|
|
}
|
|
}
|
|
|
|
func WithEntrypoint(entrypoint string) AnonymousUserOptionFunc {
|
|
return func(opts *AnonymousUserOptions) {
|
|
opts.Entrypoint = entrypoint
|
|
}
|
|
}
|
|
|
|
func WithRole(role string) AnonymousUserOptionFunc {
|
|
return func(opts *AnonymousUserOptions) {
|
|
opts.Role = role
|
|
}
|
|
}
|