forked from qor/qor-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
51 lines (42 loc) · 948 Bytes
/
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
package config
import (
"html/template"
"os"
"github.com/jinzhu/configor"
"github.com/microcosm-cc/bluemonday"
"github.com/qor/render"
)
type SMTPConfig struct {
Host string
Port string
User string
Password string
Site string
}
var Config = struct {
Port uint `default:"7000" env:"PORT"`
DB struct {
Name string `default:"qor_example"`
Adapter string `default:"mysql"`
User string
Password string
}
SMTP SMTPConfig
}{}
var (
Root = os.Getenv("GOPATH") + "/src/github.com/qor/qor-example"
View *render.Render
)
func init() {
if err := configor.Load(&Config, "config/database.yml", "config/smtp.yml"); err != nil {
panic(err)
}
View = render.New()
htmlSanitizer := bluemonday.UGCPolicy()
View.RegisterFuncMap("raw", func(str string) template.HTML {
return template.HTML(htmlSanitizer.Sanitize(str))
})
}
func (s SMTPConfig) HostWithPort() string {
return s.Host + ":" + s.Port
}