2023-09-21 05:54:08 +02:00
|
|
|
package http
|
|
|
|
|
2023-09-24 17:33:20 +02:00
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
)
|
2023-09-21 05:54:08 +02:00
|
|
|
|
|
|
|
type Options struct {
|
2023-09-24 17:33:20 +02:00
|
|
|
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"`
|
2023-09-21 05:54:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type OptionFunc func(*Options)
|
|
|
|
|
|
|
|
func DefaultOptions() *Options {
|
|
|
|
return &Options{
|
|
|
|
Logger: log.Printf,
|
|
|
|
CustomDir: "",
|
2023-09-24 17:33:20 +02:00
|
|
|
TemplateData: &TemplateData{
|
|
|
|
Title: "Rebound",
|
|
|
|
SSHPublicHost: "127.0.0.1",
|
|
|
|
SSHPublicPort: 2222,
|
|
|
|
},
|
2023-09-21 05:54:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2023-09-24 17:33:20 +02:00
|
|
|
|
|
|
|
func WithTemplateData(templateData *TemplateData) func(*Options) {
|
|
|
|
return func(opts *Options) {
|
|
|
|
opts.TemplateData = templateData
|
|
|
|
}
|
|
|
|
}
|