2023-03-20 16:40:08 +01:00
|
|
|
package http
|
|
|
|
|
2023-03-28 20:37:57 +02:00
|
|
|
import "time"
|
|
|
|
|
2023-03-20 16:40:08 +01:00
|
|
|
type LocalHandlerOptions struct {
|
2023-03-28 20:37:57 +02:00
|
|
|
RoutePrefix string
|
|
|
|
Accounts []LocalAccount
|
|
|
|
CookieDomain string
|
|
|
|
CookieDuration time.Duration
|
2023-03-20 16:40:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type LocalHandlerOptionFunc func(*LocalHandlerOptions)
|
|
|
|
|
|
|
|
func defaultLocalHandlerOptions() *LocalHandlerOptions {
|
|
|
|
return &LocalHandlerOptions{
|
2023-03-28 20:37:57 +02:00
|
|
|
RoutePrefix: "",
|
|
|
|
Accounts: make([]LocalAccount, 0),
|
|
|
|
CookieDomain: "",
|
|
|
|
CookieDuration: 24 * time.Hour,
|
2023-03-20 16:40:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithAccounts(accounts ...LocalAccount) LocalHandlerOptionFunc {
|
|
|
|
return func(opts *LocalHandlerOptions) {
|
|
|
|
opts.Accounts = accounts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithRoutePrefix(prefix string) LocalHandlerOptionFunc {
|
|
|
|
return func(opts *LocalHandlerOptions) {
|
|
|
|
opts.RoutePrefix = prefix
|
|
|
|
}
|
|
|
|
}
|
2023-03-28 20:37:57 +02:00
|
|
|
|
|
|
|
func WithCookieOptions(domain string, duration time.Duration) LocalHandlerOptionFunc {
|
|
|
|
return func(opts *LocalHandlerOptions) {
|
|
|
|
opts.CookieDomain = domain
|
|
|
|
opts.CookieDuration = duration
|
|
|
|
}
|
|
|
|
}
|