/
config.go
93 lines (87 loc) · 1.82 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package config
import (
"os"
"fmt"
"io/ioutil"
"gopkg.in/yaml.v2"
)
type Config struct {
cwd string
Port string `yaml:port`
Redis struct {
Ip string `yaml:ip`
Port string `yaml:port`
Db int `yaml:db`
}
Session struct {
Cookie string `yaml:cookie`
Key string `yaml:key`
}
Sendgrid struct {
Key string `yaml:key`
Endpoint string `yaml:endpoint`
Username string `yaml:username`
Password string `yaml:password`
}
Cassandra struct {
Ip string `yaml:ip`
Keyspace string `yaml:keyspace`
}
Datadog struct {
Connstr string `yaml:connstr`
}
Rabbit struct {
ConnectString string `yaml:connstr`
}
MailGun struct {
Key string `yaml:key`
Pub_Key string `yaml:pubkey`
Endpoint string `yaml:endpoint`
Domain string `yaml:domain`
}
Github struct {
ClientId string `yaml:clientid`
ClientSecret string `yaml:clientsecret`
Endpoint string `yaml:endpoint`
Success string `yaml:success`
Api string `yaml:api`
}
Consumers int
}
// global configuration var
var Configuration *Config
func (c *Config) SetCwd(cwd string){
c.cwd = cwd
}
func (c *Config) GetCwd() string {
return c.cwd
}
func Init(){
Configuration = &Config{}
var cwd, err = os.Getwd()
if err != nil {
panic(err)
}
Configuration.SetCwd(cwd)
LoadYaml()
}
func LoadYaml(){
file, err := os.Open(Configuration.GetCwd() + "/application.yml")
if err != nil {
fmt.Printf("Cannot load application.yml from root")
panic(err)
}
data, err := ioutil.ReadAll(file)
if err != nil {
fmt.Printf("Cannot read application.yml file, check access.")
panic(err)
}
err = yaml.Unmarshal(data, Configuration)
if err != nil {
fmt.Printf("Yaml parse failed")
panic(err)
}
if os.Getenv("port") != "" {
Configuration.Port = os.Getenv("port")
}
}