-
Notifications
You must be signed in to change notification settings - Fork 282
/
system.go
60 lines (53 loc) · 1.86 KB
/
system.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
package system
import (
"io/ioutil"
"github.com/go-yaml/yaml"
)
type Configuration struct {
SignupEnabled bool `yaml:"signup_enabled"` // signup enabled or not
QiniuAccessKey string `yaml:"qiniu_accesskey"` // qiniu
QiniuSecretKey string `yaml:"qiniu_secretkey"`
QiniuFileServer string `yaml:"qiniu_fileserver"`
QiniuBucket string `yaml:"qiniu_bucket"`
GithubClientId string `yaml:"github_clientid"` // github
GithubClientSecret string `yaml:"github_clientsecret"`
GithubAuthUrl string `yaml:"github_authurl"`
GithubRedirectURL string `yaml:"github_redirecturl"`
GithubTokenUrl string `yaml:"github_tokenurl"`
GithubScope string `yaml:"github_scope"`
SmtpUsername string `yaml:"smtp_username"` // username
SmtpPassword string `yaml:"smtp_password"` //password
SmtpHost string `yaml:"smtp_host"` //host
SessionSecret string `yaml:"session_secret"` //session_secret
Domain string `yaml:"domain"` //domain
Public string `yaml:"public"` //public
Addr string `yaml:"addr"` //addr
BackupKey string `yaml:"backup_key"` //backup_key
DSN string `yaml:"dsn"` //database dsn
NotifyEmails string `yaml:"notify_emails"` //notify_emails
PageSize int `yaml:"page_size"` //page_size
SmmsFileServer string `yaml:"smms_fileserver"`
}
const (
DEFAULT_PAGESIZE = 10
)
var configuration *Configuration
func LoadConfiguration(path string) error {
data, err := ioutil.ReadFile(path)
if err != nil {
return err
}
var config Configuration
err = yaml.Unmarshal(data, &config)
if err != nil {
return err
}
if config.PageSize <= 0 {
config.PageSize = DEFAULT_PAGESIZE
}
configuration = &config
return err
}
func GetConfiguration() *Configuration {
return configuration
}