/
config.go
executable file
·63 lines (51 loc) · 1.27 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
package service
import (
"encoding/json"
"github.com/harveywangdao/ants/logger"
"gopkg.in/yaml.v2"
"io/ioutil"
)
const (
configPath = "conf/app.yaml"
)
var config Config
type LogConfig struct {
LogPath string `yaml:"logPath" json:"logPath"`
LogLevel string `yaml:"logLevel" json:"logLevel"`
}
type EtcdConfig struct {
Endpoints []string `yaml:"endpoints" json:"endpoints"`
}
type ServerConfig struct {
Name string `yaml:"name" json:"name"`
Port string `yaml:"port" json:"port"`
}
type HttpServerConfig struct {
Port string `yaml:"port" json:"port"`
HttpsPort string `yaml:"httpsPort" json:"httpsPort"`
PrefixUrl string `yaml:"prefixUrl" json:"prefixUrl"`
}
type Config struct {
Log *LogConfig `yaml:"log" json:"log"`
Etcd *EtcdConfig `yaml:"etcd" json:"etcd"`
Server *ServerConfig `yaml:"server" json:"server"`
HttpServer *HttpServerConfig `yaml:"httpServer" json:"httpServer"`
}
func initConfig() error {
confData, err := ioutil.ReadFile(configPath)
if err != nil {
logger.Error(err)
return err
}
err = yaml.Unmarshal(confData, &config)
if err != nil {
logger.Error(err)
return err
}
data, _ := json.Marshal(&config)
logger.Info("config:", string(data))
return nil
}
func getConf() *Config {
return &config
}