61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
package http
|
|
|
|
import (
|
|
"log"
|
|
|
|
"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_"`
|
|
Stats *stat.Store
|
|
}
|
|
|
|
type TemplateData struct {
|
|
Title string `env:"TITLE"`
|
|
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,
|
|
},
|
|
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
|
|
}
|
|
}
|
|
|
|
func WithStats(stats *stat.Store) func(*Options) {
|
|
return func(opts *Options) {
|
|
opts.Stats = stats
|
|
}
|
|
}
|