forked from extrame/goblet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configer.go
42 lines (34 loc) · 813 Bytes
/
configer.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
package goblet
import (
"bytes"
"flag"
"io"
"os"
"path/filepath"
)
type Configer interface {
GetConfigSource(s *Server) (io.Reader, error)
}
type YamlConfiger struct {
}
func (c *YamlConfiger) GetConfigSource(s *Server) (io.Reader, error) {
if s.cfgFileSuffix == "" {
s.cfgFileSuffix = "conf"
}
flag.StringVar(&s.ConfigFile, "config", "./"+s.Name+"."+s.cfgFileSuffix, "设置配置文件的路径")
flag.Parse()
s.ConfigFile = filepath.FromSlash(s.ConfigFile)
return os.Open(s.ConfigFile)
}
//StringConfiger is a configer that read config from a string
type StringConfiger struct {
Content string
}
const BasicConfig = `
basic:
env: development
db_engine: none
`
func (c *StringConfiger) GetConfigSource(s *Server) (io.Reader, error) {
return bytes.NewReader([]byte(c.Content)), nil
}