-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
78 lines (73 loc) · 1.35 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
package main
import (
"os"
"strconv"
)
// Config ...
type Config struct {
Port int
Jwt struct {
Private string
Public string
}
Mongodb struct {
Host string
Database string
Username string
Password string
}
Mssql struct {
Host string
Database string
Username string
Password string
Port int
SCHEMA0 string
SCHEMA2 string
SCHEMA3 string
}
Socket struct {
URL string
}
Redisdb struct {
Addr string
Password string
DB int
}
}
// GetByENV is get config by environment variable
func (c *Config) GetByENV() {
// port
if val, ok := os.LookupEnv("PORT"); ok {
if Num, err := strconv.Atoi(val); err == nil {
c.Port = Num
}
}
// mssql
c.Mssql.Port = 1433 // default
if val, ok := os.LookupEnv("MSSQL_HOST"); ok {
c.Mssql.Host = val
}
if val, ok := os.LookupEnv("MSSQL_DB"); ok {
c.Mssql.Database = val
}
if val, ok := os.LookupEnv("MSSQL_USERNAME"); ok {
c.Mssql.Username = val
}
if val, ok := os.LookupEnv("MSSQL_PASSWORD"); ok {
c.Mssql.Password = val
}
// mongo
if val, ok := os.LookupEnv("MONGO_HOST"); ok {
c.Mongodb.Host = val
}
if val, ok := os.LookupEnv("MONGO_DB"); ok {
c.Mongodb.Database = val
}
if val, ok := os.LookupEnv("MONGO_USERNAME"); ok {
c.Mongodb.Username = val
}
if val, ok := os.LookupEnv("MONGO_PASSWORD"); ok {
c.Mongodb.Password = val
}
}