feat: initial commit
This commit is contained in:
38
internal/http/handler/webui/options.go
Normal file
38
internal/http/handler/webui/options.go
Normal file
@ -0,0 +1,38 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/sessions"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
BaseURL string
|
||||
SessionStore sessions.Store
|
||||
Mounts map[string]http.Handler
|
||||
}
|
||||
|
||||
type OptionFunc func(opts *Options)
|
||||
|
||||
func NewOptions(funcs ...OptionFunc) *Options {
|
||||
opts := &Options{
|
||||
BaseURL: "",
|
||||
Mounts: make(map[string]http.Handler),
|
||||
}
|
||||
for _, fn := range funcs {
|
||||
fn(opts)
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
func WithBaseURL(baseURL string) OptionFunc {
|
||||
return func(opts *Options) {
|
||||
opts.BaseURL = baseURL
|
||||
}
|
||||
}
|
||||
|
||||
func WithMount(mountpoint string, handler http.Handler) OptionFunc {
|
||||
return func(opts *Options) {
|
||||
opts.Mounts[mountpoint] = handler
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user