2023-09-21 05:54:08 +02:00
|
|
|
package ssh
|
2023-09-09 04:00:00 +02:00
|
|
|
|
|
|
|
import "log"
|
|
|
|
|
|
|
|
type Options struct {
|
|
|
|
Logger func(message string, args ...any)
|
2023-09-21 05:54:08 +02:00
|
|
|
SockDir string `env:"SOCK_DIR"`
|
|
|
|
PublicPort uint `env:"PUBLIC_PORT"`
|
|
|
|
PublicHost string `env:"PUBLIC_HOST"`
|
|
|
|
HostKey string `env:"HOST_KEY"`
|
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",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
}
|