-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
97 lines (87 loc) · 2.25 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"fmt"
common "github.com/voidshard/wysteria/common"
wcm "github.com/voidshard/wysteria/common/middleware"
wdb "github.com/voidshard/wysteria/server/database"
wsi "github.com/voidshard/wysteria/server/instrumentation"
wsb "github.com/voidshard/wysteria/server/searchbase"
"log"
"os"
"path/filepath"
)
type configuration struct {
Database wdb.Settings
Searchbase wsb.Settings
Middleware wcm.Settings
Health wsi.WebserverConfig
Instrumentation map[string]*wsi.Settings
}
// Load the server side configuration from somewhere.
// Load order:
// - local .ini file(s) if they are in the cwd, if found
// - .ini filepath given by wysteria os.Env variable, if set
// - default values
//
func loadConfig(in string) *configuration {
cnf := &configuration{}
if in != "" {
err := common.ReadConfig(in, cnf)
if err != nil {
panic(err) // We can't read the config explicitly given to us by the user -> panic
}
return cnf
}
// Otherwise, try to find a suitable config
fpath, err := common.ChooseServerConfig()
if err == nil {
log.Println("Attempting to read", fpath, cnf, err)
err := common.ReadConfig(fpath, cnf)
if err != nil {
log.Println(fmt.Sprintf("Unable to read config '%s' %s", fpath, err))
} else {
return cnf
}
}
// If that fails, use default settings
log.Println("WARNING: No config found, using OS temporary folders for storage.")
return makeDefaults()
}
// Get the default settings.
//
func makeDefaults() *configuration {
return &configuration{
wdb.Settings{
Driver: wdb.DriverBolt,
Database: filepath.Join(os.TempDir(), "wysteria_db"),
},
wsb.Settings{
Driver: wsb.DriverBleve,
Host: "",
Port: 0,
User: "",
Pass: "",
Database: filepath.Join(os.TempDir(), "wysteria_sb"),
PemFile: "",
},
wcm.Settings{
Driver: wcm.DriverNats,
Config: "",
SSLEnableTLS: false,
SSLVerify: false,
SSLCert: "",
SSLKey: "",
},
wsi.WebserverConfig{
Port: 8150,
EndpointHealth: "/health",
},
map[string]*wsi.Settings{
"default": &wsi.Settings{
Driver: wsi.DriverLogfile,
Location: filepath.Join(os.TempDir(), "wysteria_logs"),
Target: "out.log",
},
},
}
}