/
config.go
65 lines (54 loc) · 1.51 KB
/
config.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 server
import (
"errors"
"github.com/chzyer/flagly"
"github.com/chzyer/flow"
"github.com/chzyer/logex"
"github.com/chzyer/next/dchan"
"github.com/chzyer/next/ip"
)
func init() {
flagly.RegisterAll(ip.IPNet{})
}
type Config struct {
Debug bool `desc:"turn on debug"`
DebugStack bool `default:"true"`
DebugFlow bool
DebugTun bool
ChannelType string `name:"chantype" default:"tcp"`
HTTP string `desc:"listen http port" default:":11311"`
HTTPAes string `name:"key" desc:"http aes key; required"`
HTTPCert string `desc:"https cert file path"`
HTTPKey string `desc:"https key file path"`
Sock string `desc:"unixsock for interactive with" default:"/tmp/next.sock"`
MTU int `default:"1500"`
Net *ip.IPNet `default:"10.8.0.1/24"`
Pprof string `default:":10060"`
DevId int
DBPath string `desc:"filepath to persist user info" default:"nextuser"`
}
func (c *Config) FlaglyVerify() error {
if c.Net == nil {
return errors.New("net is empty")
}
if c.HTTPAes == "" {
return errors.New("httpaes is required, please try `next genkey` to genreate one")
}
if c.DBPath == "" {
return errors.New("dbpath is empty")
}
if err := dchan.CheckType(c.ChannelType); err != nil {
return logex.Trace(err)
}
flow.DefaultDebug = c.DebugFlow
logex.ShowCode = c.DebugStack
return nil
}
func (c *Config) FlaglyHandle(f *flow.Flow, h *flagly.Handler) error {
srv := New(c, f)
srv.Run()
return nil
}
func (c *Config) FlaglyDesc() string {
return "server mode"
}