forked from GoAdminGroup/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
110 lines (90 loc) · 2.23 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2018 cg33. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package config
import (
"html/template"
"sync"
)
// Database is a type of database connection config.
// Because a little difference of different database driver.
// The Config has multiple options but may be not used.
// Such as the sqlite driver only use the FILE option which
// can be ignored when the driver is mysql.
type Database struct {
HOST string
PORT string
USER string
PWD string
NAME string
MAX_IDLE_CON int
MAX_OPEN_CON int
DRIVER string
FILE string
}
// Store is the file store config. Path is the local store path.
// and prefix is the url prefix used to visit it.
type Store struct {
PATH string
PREFIX string
}
// Config type is the global config of goAdmin. It will be
// initialized in the engine.
type Config struct {
// An array supports multi database connection. The first
// element of DATABASE is the default connection. See the
// file connection.go.
DATABASE []Database
// The cookie domain used in the auth modules. see
// the session.go.
DOMAIN string
// Used to set as the localize language which show in the
// interface.
LANGUAGE string
// The global url prefix.
PREFIX string
// The theme name of template.
THEME string
// The path where files will be stored into.
STORE Store
// The title of web page.
TITLE string
// Logo is the top text in the sidebar.
LOGO template.HTML
// Mini-logo is the top text in the sidebar when folding.
MINILOGO template.HTML
// The url redirect to after login
INDEX string
}
var (
globalCfg Config
mutex sync.Mutex
)
// Set sets the config.
func Set(cfg Config) {
mutex.Lock()
globalCfg = cfg
if globalCfg.TITLE == "" {
globalCfg.TITLE = "GoAdmin"
}
if globalCfg.LOGO == "" {
globalCfg.LOGO = "<b>Go</b>Admin"
}
if globalCfg.MINILOGO == "" {
globalCfg.MINILOGO = "<b>G</b>A"
}
if globalCfg.THEME == "" {
globalCfg.THEME = "adminlte"
}
if globalCfg.INDEX == "" {
globalCfg.INDEX = "/info/manager"
}
if globalCfg.INDEX == "/" {
globalCfg.INDEX = ""
}
mutex.Unlock()
}
// Get gets the config.
func Get() Config {
return globalCfg
}