-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.go
76 lines (67 loc) · 1.75 KB
/
configure.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
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"encoding/json"
"flag"
"log"
"os"
)
type TransportWs struct {
Listen string `json:"listen"`
Path string `json:"path"`
Tls bool `json:"tls"`
CertPath string `json:"certPath"`
KeyPath string `json:"keyPath"`
}
type TransportTls struct {
Listen string `json:"listen"`
CertPath string `json:"certPath"`
KeyPath string `json:"keyPath"`
}
type Config struct {
SshAddr string `json:"SshAddr"`
Ws TransportWs `json:"ws"`
Tls TransportTls `json:"tls"`
}
func LoadConfig() Config {
// TODO: Load config from Command-Line Flags
ssh := flag.String("ssh", "127.0.0.1:22", "SSH address")
// WS
wsListen := flag.String("ws-listen", "", "Websocket listen address")
wsPath := flag.String("ws-path", "/", "Websocket path")
wsTls := flag.Bool("ws-tls", false, "Enable TLS for websocket")
wsCert := flag.String("ws-cert", "cert.pem", "Certificate path for wss")
wsKey := flag.String("ws-key", "key.pem", "Key path for wss")
// TLS
tlsListen := flag.String("tls-listen", "", "Websocket listen address")
tlsCert := flag.String("tls-cert", "cert.pem", "Certificate path for tls")
tlsKey := flag.String("tls-key", "key.pem", "Key path for tls")
flag.Parse()
if len(os.Args) == 1 {
// Load config from file
cfile, cfile_err := os.ReadFile("config.json")
if cfile_err != nil {
log.Fatalln(cfile_err.Error())
}
conf := Config{}
conf_err := json.Unmarshal(cfile, &conf)
if conf_err != nil {
log.Fatalln(conf_err.Error())
}
return conf
}
return Config{
SshAddr: *ssh,
Ws: TransportWs{
Listen: *wsListen,
Path: *wsPath,
Tls: *wsTls,
CertPath: *wsCert,
KeyPath: *wsKey,
},
Tls: TransportTls{
Listen: *tlsListen,
CertPath: *tlsCert,
KeyPath: *tlsKey,
},
}
}