-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.go
40 lines (33 loc) · 831 Bytes
/
main.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
package main
import (
"flag"
"fmt"
"log"
"github.com/pelletier/go-toml"
)
func main() {
var configPath string
var showVersion bool
flag.StringVar(&configPath, "c", "", "configuration file, default to 'config.toml'")
flag.BoolVar(&showVersion, "v", false, "show version information")
flag.Parse()
if showVersion {
fmt.Println("Subsocks", Version)
return
}
if configPath == "" {
configPath = "config.toml"
log.Printf("Using default configuration 'config.toml'")
}
config, err := toml.LoadFile(configPath)
if err != nil {
log.Fatalf("Load configuration failed: %s", err)
}
if c, ok := config.Get("client").(*toml.Tree); ok {
launchClient(c)
} else if s, ok := config.Get("server").(*toml.Tree); ok {
launchServer(s)
} else {
log.Fatalf("No valid configuration '[client]' or '[server]'")
}
}