-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
46 lines (40 loc) · 1.12 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
package sky
import (
"fmt"
"github.com/spf13/viper"
)
// Home home url
func Home() string {
if IsProduction() {
name := viper.GetString("server.name")
if viper.GetBool("server.ssl") {
return "https://" + name
}
return "http://" + name
}
return fmt.Sprintf("http://localhost:%d", viper.GetInt("server.port"))
}
// IsProduction production mode ?
func IsProduction() bool {
return viper.GetString("env") == "production"
}
// DataSource database source url
func DataSource() string {
//"user=%s password=%s host=%s port=%d dbname=%s sslmode=%s"
args := ""
for k, v := range viper.GetStringMapString("database.args") {
args += fmt.Sprintf(" %s=%s ", k, v)
}
return args
//"postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full")
// return fmt.Sprintf(
// "%s://%s:%s@%s:%d/%s?sslmode=%s",
// viper.GetString("database.driver"),
// viper.GetString("database.args.user"),
// viper.GetString("database.args.password"),
// viper.GetString("database.args.host"),
// viper.GetInt("database.args.port"),
// viper.GetString("database.args.dbname"),
// viper.GetString("database.args.sslmode"),
// )
}