-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
64 lines (55 loc) · 1.13 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
package app
import (
"fmt"
"log"
"github.com/spf13/viper"
)
type DataBaseConfig struct {
host string
port string
user string
pass string
name string
}
type AppConfig struct {
SessionKey string
Port string
DatabaseURL string
}
type Config struct {
App *AppConfig
DB *DataBaseConfig
}
func NewConfig() *Config {
viper.SetConfigFile(ConfigPath)
err := viper.ReadInConfig()
if err != nil {
panic(err)
}
if viper.GetBool(`debug`) {
log.Println("Service RUN on DEBUG mode")
}
dbHost := viper.GetString(`database.host`)
dbPort := viper.GetString(`database.port`)
dbUser := viper.GetString(`database.user`)
dbPass := viper.GetString(`database.pass`)
dbName := viper.GetString(`database.name`)
appPort := viper.GetString(`server.address`)
connection := fmt.Sprintf(
"host=%s dbname=%s sslmode=disable port=%s password=%s user=%s",
dbHost, dbName, dbPort, dbPass, dbUser)
return &Config{
DB: &DataBaseConfig{
host: dbHost,
port: dbPort,
user: dbUser,
pass: dbPass,
name: dbName,
},
App: &AppConfig{
SessionKey: "dsdsdsds",
DatabaseURL: connection,
Port: appPort,
},
}
}