-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
58 lines (51 loc) · 975 Bytes
/
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
package configgo
import (
"fmt"
)
type Config struct {
config any
settings Setting
items []*configItem
}
func newConfig(inst any, settings Setting, items []*configItem) *Config {
config := &Config{
config: inst,
settings: settings,
items: items,
}
config.SetEnv(newEnv())
return config
}
func (c *Config) Process() (err error) {
for _, item := range c.items {
item.Process()
}
if c.hasErrors() {
return fmt.Errorf("%s", c.GetErrorsMessage())
}
return nil
}
func (c *Config) SetEnv(env IEnv) *Config {
for _, item := range c.items {
item.SetEnv(env)
}
return c
}
func (c Config) GetErrorsMessage() string {
result := ""
if len(c.settings.Title) > 0 {
result = result + c.settings.Title + "\n"
}
for _, item := range c.items {
result = result + item.GetErrorsMessage() + "\n"
}
return result
}
func (c Config) hasErrors() bool {
for _, item := range c.items {
if item.HasError() {
return true
}
}
return false
}