rebound/option.go

56 lines
1.1 KiB
Go

package rebound
import "log"
type Options struct {
Address string `env:"REBOUND_ADDRESS"`
Logger func(message string, args ...any)
SockDir string `env:"REBOUND_SOCK_DIR"`
PublicPort uint `env:"REBOUND_PUBLIC_PORT"`
PublicHost string `env:"REBOUND_PUBLIC_HOST"`
HostKey string `env:"REBOUND_HOST_KEY"`
}
type OptionFunc func(*Options)
func DefaultOptions() *Options {
return &Options{
Address: "127.0.0.1:2222",
SockDir: "./socks",
Logger: log.Printf,
PublicPort: 2222,
PublicHost: "127.0.0.1",
HostKey: "./host.key",
}
}
func WithAddress(addr string) func(*Options) {
return func(opts *Options) {
opts.Address = addr
}
}
func WithSockDir(addr string) func(*Options) {
return func(opts *Options) {
opts.SockDir = addr
}
}
func WithPublicHost(host string) func(*Options) {
return func(opts *Options) {
opts.PublicHost = host
}
}
func WithPublicPort(port uint) func(*Options) {
return func(opts *Options) {
opts.PublicPort = port
}
}
func WithHostKey(key string) func(*Options) {
return func(opts *Options) {
opts.HostKey = key
}
}