42 lines
729 B
Go
42 lines
729 B
Go
|
package http
|
||
|
|
||
|
import "github.com/gorilla/sessions"
|
||
|
|
||
|
type Options struct {
|
||
|
Address string
|
||
|
BaseURL string
|
||
|
SessionStore sessions.Store
|
||
|
}
|
||
|
|
||
|
type OptionFunc func(opts *Options)
|
||
|
|
||
|
func NewOptions(funcs ...OptionFunc) *Options {
|
||
|
opts := &Options{
|
||
|
Address: ":3000",
|
||
|
BaseURL: "",
|
||
|
SessionStore: sessions.NewCookieStore(),
|
||
|
}
|
||
|
for _, fn := range funcs {
|
||
|
fn(opts)
|
||
|
}
|
||
|
return opts
|
||
|
}
|
||
|
|
||
|
func WithBaseURL(baseURL string) OptionFunc {
|
||
|
return func(opts *Options) {
|
||
|
opts.BaseURL = baseURL
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func WithAddress(addr string) OptionFunc {
|
||
|
return func(opts *Options) {
|
||
|
opts.Address = addr
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func WithSessionStore(store sessions.Store) OptionFunc {
|
||
|
return func(opts *Options) {
|
||
|
opts.SessionStore = store
|
||
|
}
|
||
|
}
|