forked from kodekloudhub/go-webapp-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
72 lines (66 loc) · 1.76 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
package config
import (
"flag"
"fmt"
"os"
"github.com/jinzhu/configor"
)
// Config represents the composition of yml settings.
type Config struct {
Database struct {
Dialect string `default:"sqlite3"`
Host string `default:"book.db"`
Port string
Dbname string
Username string
Password string
Migration bool `default:"false"`
}
Redis struct {
Enabled bool `default:"false"`
ConnectionPoolSize int `yaml:"connection_pool_size" default:"10"`
Host string
Port string
}
Extension struct {
MasterGenerator bool `yaml:"master_generator" default:"false"`
CorsEnabled bool `yaml:"cors_enabled" default:"false"`
SecurityEnabled bool `yaml:"security_enabled" default:"false"`
}
Log struct {
RequestLogFormat string `yaml:"request_log_format" default:"${remote_ip} ${account_name} ${uri} ${method} ${status}"`
}
StaticContents struct {
Path string `yaml:"path"`
}
Security struct {
AuthPath []string `yaml:"auth_path"`
ExculdePath []string `yaml:"exclude_path"`
UserPath []string `yaml:"user_path"`
AdminPath []string `yaml:"admin_path"`
}
}
const (
// DEV represents development environment
DEV = "develop"
// PRD represents production environment
PRD = "production"
// DOC represents docker container
DOC = "docker"
)
// Load reads the settings written to the yml file
func Load() (*Config, string) {
var env *string
if value := os.Getenv("WEB_APP_ENV"); value != "" {
env = &value
} else {
env = flag.String("env", "develop", "To switch configurations.")
flag.Parse()
}
config := &Config{}
if err := configor.Load(config, "application."+*env+".yml"); err != nil {
fmt.Printf("Failed to read application.%s.yml: %s", *env, err)
os.Exit(2)
}
return config, *env
}