-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
65 lines (54 loc) · 1.3 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package tsn
import (
"github.com/awlsring/texit/internal/pkg/logger"
"github.com/rs/zerolog"
"tailscale.com/tsnet"
)
type ServerOption func(*tsnet.Server)
func WithStandardLoggingFunc(lvl zerolog.Level) ServerOption {
tailog := logger.InitLogger(lvl).With().Str("tsn", "server").Logger()
return func(s *tsnet.Server) {
s.Logf = func(format string, args ...interface{}) {
tailog.Debug().Msgf(format, args...)
}
}
}
func WithAuthKey(authKey string) ServerOption {
return func(s *tsnet.Server) {
s.AuthKey = authKey
}
}
func WithHostname(hostname string) ServerOption {
return func(s *tsnet.Server) {
s.Hostname = hostname
}
}
func WithStateDir(stateDir string) ServerOption {
return func(s *tsnet.Server) {
s.Dir = stateDir
}
}
func WithControlURL(controlURL string) ServerOption {
return func(s *tsnet.Server) {
s.ControlURL = controlURL
}
}
func WithRunWebClient(runWebClient bool) ServerOption {
return func(s *tsnet.Server) {
s.RunWebClient = runWebClient
}
}
func WithLogFunc(logFunc func(format string, args ...interface{})) ServerOption {
return func(s *tsnet.Server) {
s.Logf = logFunc
}
}
func NewServer(options ...ServerOption) *tsnet.Server {
s := &tsnet.Server{
Logf: func(format string, args ...interface{}) {},
}
for _, opt := range options {
opt(s)
}
return s
}