/
loadSecurity.go
41 lines (35 loc) · 1.02 KB
/
loadSecurity.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
package security
import (
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
)
//load database configuration from file. Including PostgreSQL and Redis.
type DbSecurity struct {
ThePgSecurity PgSecurity `yaml:"PostgreSQL"`
TheRedisSecurity RedisSecurity `yaml:"Redis"`
}
type PgSecurity struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"`
DbName string `yaml:"dbname"`
Sslmode string `yaml:"sslmode"`
//"host=ras-pg user=postgres password=%s dbname=ras sslmode=disable"
}
type RedisSecurity struct {
Host string `yaml:"host"`
//Password string `yaml:"password"`
}
func LoadDbSecurity(filepath string) (dbSec DbSecurity, err error) {
dbSecFile, err := ioutil.ReadFile(filepath)
if err != nil {
return DbSecurity{}, fmt.Errorf("LoadDbSecurity ioutil.ReadFile error: %v", err)
}
err = yaml.Unmarshal(dbSecFile, &dbSec)
if err != nil {
return DbSecurity{}, fmt.Errorf("LoadDbSecurity yaml.Unmarshal error: %v", err)
}
return dbSec, nil
}