rebound/ssh/options.go

66 lines
1.2 KiB
Go
Raw Normal View History

package ssh
2023-09-09 04:00:00 +02:00
2023-09-24 20:21:44 +02:00
import (
"log"
"forge.cadoles.com/wpetit/rebound/stat"
)
2023-09-09 04:00:00 +02:00
type Options struct {
Logger func(message string, args ...any)
SockDir string `env:"SOCK_DIR"`
PublicPort uint `env:"PUBLIC_PORT"`
PublicHost string `env:"PUBLIC_HOST"`
HostKey string `env:"HOST_KEY"`
2023-09-24 20:21:44 +02:00
Stats *stat.Store
2023-09-09 04:00:00 +02:00
}
type OptionFunc func(*Options)
func DefaultOptions() *Options {
return &Options{
SockDir: "./socks",
Logger: log.Printf,
PublicPort: 2222,
PublicHost: "127.0.0.1",
HostKey: "./host.key",
2023-09-24 20:21:44 +02:00
Stats: stat.NewStore(),
2023-09-09 04:00:00 +02:00
}
}
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
}
}
func WithLogger(logger func(message string, args ...any)) func(*Options) {
return func(opts *Options) {
opts.Logger = logger
}
}
2023-09-24 20:21:44 +02:00
func WithStats(stats *stat.Store) func(*Options) {
return func(opts *Options) {
opts.Stats = stats
}
}