rebound/http/options.go

61 lines
1.2 KiB
Go
Raw Permalink Normal View History

package http
import (
"log"
2023-09-24 20:21:44 +02:00
"forge.cadoles.com/wpetit/rebound/stat"
)
type Options struct {
Logger func(message string, args ...any)
CustomDir string `env:"CUSTOM_DIR"`
TemplateData *TemplateData `envPrefix:"TEMPLATE_DATA_"`
2023-09-24 20:21:44 +02:00
Stats *stat.Store
}
type TemplateData struct {
Title string `env:"TITLE"`
2023-09-24 20:21:44 +02:00
Version string
SSHPublicHost string `env:"SSH_PUBLIC_HOST"`
SSHPublicPort int `env:"SSH_PUBLIC_PORT"`
}
type OptionFunc func(*Options)
func DefaultOptions() *Options {
return &Options{
Logger: log.Printf,
CustomDir: "",
TemplateData: &TemplateData{
Title: "Rebound",
SSHPublicHost: "127.0.0.1",
SSHPublicPort: 2222,
},
2023-09-24 20:21:44 +02:00
Stats: stat.NewStore(),
}
}
func WithLogger(logger func(message string, args ...any)) func(*Options) {
return func(opts *Options) {
opts.Logger = logger
}
}
func WithCustomDir(customDir string) func(*Options) {
return func(opts *Options) {
opts.CustomDir = customDir
}
}
func WithTemplateData(templateData *TemplateData) func(*Options) {
return func(opts *Options) {
opts.TemplateData = templateData
}
}
2023-09-24 20:21:44 +02:00
func WithStats(stats *stat.Store) func(*Options) {
return func(opts *Options) {
opts.Stats = stats
}
}