forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
78 lines (68 loc) · 1.68 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
package editor
import (
"github.com/imdario/mergo"
"os"
)
// Default values for the configuration
const (
DefaultPort = 4444
)
// Config the configs for the Editor plugin
type Config struct {
// Hostname if empty used the iris server's hostname
Hostname string
// Port if 0 4444
Port int
// KeyFile the key file(ssl optional)
KeyFile string
// CertFile the cert file (ssl optional)
CertFile string
// WorkingDir if empty "./"
WorkingDir string
// Username defaults to empty, you should set this
Username string
// Password defaults to empty, you should set this
Password string
// DisableOutput set that to true if you don't care about alm-tools' messages
// they are useful because that the default value is "false"
DisableOutput bool
}
// DefaultConfig returns the default configs for the Editor plugin
func DefaultConfig() Config {
// explicit
return Config{
Hostname: "",
Port: 4444,
KeyFile: "",
CertFile: "",
WorkingDir: "." + string(os.PathSeparator), // alm-tools should end with path separator.
Username: "",
Password: "",
DisableOutput: false,
}
}
// Merge merges the default with the given config and returns the result
func (c Config) Merge(cfg []Config) (config Config) {
if len(cfg) > 0 {
config = cfg[0]
if err := mergo.Merge(&config, c); err != nil {
if !c.DisableOutput {
panic(err)
}
}
} else {
_default := c
config = _default
}
return
}
// MergeSingle merges the default with the given config and returns the result
func (c Config) MergeSingle(cfg Config) (config Config) {
config = cfg
if err := mergo.Merge(&config, c); err != nil {
if !c.DisableOutput {
panic(err)
}
}
return
}