rebound/http/options.go

50 lines
1009 B
Go

package http
import (
"log"
)
type Options struct {
Logger func(message string, args ...any)
CustomDir string `env:"CUSTOM_DIR"`
TemplateData *TemplateData `envPrefix:"TEMPLATE_DATA_"`
}
type TemplateData struct {
Title string `env:"TITLE"`
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,
},
}
}
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
}
}