-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
51 lines (44 loc) · 1.06 KB
/
config.go
File metadata and controls
51 lines (44 loc) · 1.06 KB
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
package main
import (
"encoding/json"
"os"
)
type Config struct {
ExitNode string `json:"exit_node"`
Hostname string `json:"hostname"`
AuthKey string `json:"authkey"`
ProxyPort int `json:"proxy_port"`
Verbose bool `json:"verbose"`
ExportListeners bool `json:"export_listeners"`
ExportAllowPorts string `json:"export_allow_ports"`
ExportDenyPorts string `json:"export_deny_ports"`
ExportMax int `json:"export_max"`
}
func LoadConfig(path string) (*Config, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}
var config Config
if err := json.Unmarshal(data, &config); err != nil {
return nil, err
}
// Set defaults
if config.Hostname == "" {
config.Hostname = "tailproxy"
}
if config.ProxyPort == 0 {
config.ProxyPort = 1080
}
if config.ExportMax == 0 {
config.ExportMax = 32
}
return &config, nil
}
func (c *Config) Save(path string) error {
data, err := json.MarshalIndent(c, "", " ")
if err != nil {
return err
}
return os.WriteFile(path, data, 0600)
}