edge/pkg/module/auth/http/options.go

50 lines
1.1 KiB
Go

package http
import (
"net/http"
"time"
)
type GetCookieDomainFunc func(r *http.Request) (string, error)
func defaultGetCookieDomain(r *http.Request) (string, error) {
return "", nil
}
type LocalHandlerOptions struct {
RoutePrefix string
Accounts []LocalAccount
GetCookieDomain GetCookieDomainFunc
CookieDuration time.Duration
}
type LocalHandlerOptionFunc func(*LocalHandlerOptions)
func defaultLocalHandlerOptions() *LocalHandlerOptions {
return &LocalHandlerOptions{
RoutePrefix: "",
Accounts: make([]LocalAccount, 0),
GetCookieDomain: defaultGetCookieDomain,
CookieDuration: 24 * time.Hour,
}
}
func WithAccounts(accounts ...LocalAccount) LocalHandlerOptionFunc {
return func(opts *LocalHandlerOptions) {
opts.Accounts = accounts
}
}
func WithRoutePrefix(prefix string) LocalHandlerOptionFunc {
return func(opts *LocalHandlerOptions) {
opts.RoutePrefix = prefix
}
}
func WithCookieOptions(getCookieDomain GetCookieDomainFunc, duration time.Duration) LocalHandlerOptionFunc {
return func(opts *LocalHandlerOptions) {
opts.GetCookieDomain = getCookieDomain
opts.CookieDuration = duration
}
}