-
Notifications
You must be signed in to change notification settings - Fork 43
/
conf.go
97 lines (79 loc) · 1.98 KB
/
conf.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 neo
import (
"time"
"net/http"
"github.com/BurntSushi/toml"
)
const (
BYTE = 1.0
KILOBYTE = 1024 * BYTE
MEGABYTE = 1024 * KILOBYTE
GIGABYTE = 1024 * MEGABYTE
TERABYTE = 1024 * GIGABYTE
)
///////////////////////////////////////////////////////////////////
// `Hotreload` section
///////////////////////////////////////////////////////////////////
type HotReloadConf struct {
Suffixes []string
Ignore []string
}
type LoggerConf struct {
Name string
Level string
}
///////////////////////////////////////////////////////////////////
// `App` section
///////////////////////////////////////////////////////////////////
type ApplicationConf struct {
Test string
Args []string
Addr string
ReadTimeout time.Duration
WriteTimeout time.Duration
// default to http.DefaultMaxHeaderBytes
MaxHeaderBytes int
// Default 10MB
MaxBodyBytes int64
Logger LoggerConf
}
///////////////////////////////////////////////////////////////////
// `Neo` section
///////////////////////////////////////////////////////////////////
type NeoConf struct {
Logger LoggerConf
}
///////////////////////////////////////////////////////////////////
// `Global` section
///////////////////////////////////////////////////////////////////
// Neo Application configuration
type Conf struct {
Hotreload HotReloadConf
App ApplicationConf
Neo NeoConf
}
func (c *Conf) loadDefaults() {
// hotreload
c.Hotreload.Ignore = []string{}
c.Hotreload.Suffixes = []string{}
// app
c.App.Args = []string{}
c.App.Addr = ":3000"
c.App.Logger.Level = "INFO"
c.App.Logger.Name = "application"
c.App.MaxHeaderBytes = http.DefaultMaxHeaderBytes
c.App.MaxBodyBytes = 10 * MEGABYTE
c.App.ReadTimeout = 0
c.App.WriteTimeout = 0
}
// Will try to parse TOML configuration file.
func (c *Conf) Parse(path string) {
c.loadDefaults()
if path == "" {
log.Info("Loaded configuration defaults")
return
}
if _, err := toml.DecodeFile(path, c); err != nil {
panic(err)
}
}