/
config.go
48 lines (38 loc) · 915 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
package common
import (
"strings"
"github.com/webx-top/echo"
"github.com/admpub/nging/v4/application/library/config/subconfig/scookie"
)
const (
ConfigName = `ConfigFromFile`
SettingName = `ConfigFromDB`
)
// APIKeyGetter API Key
type APIKeyGetter interface {
APIKey() string
}
type CookieConfigGetter interface {
CookieConfig() scookie.Config
}
func CookieConfig() scookie.Config {
return echo.Get(ConfigName).(CookieConfigGetter).CookieConfig()
}
func Setting(group ...string) echo.H {
return echo.GetStoreByKeys(SettingName, group...)
}
func BackendURL(ctx echo.Context) string {
backendURL := Setting(`base`).String(`backendURL`)
if len(backendURL) == 0 {
if ctx == nil {
return backendURL
}
backendURL = ctx.Site()
}
backendURL = strings.TrimSuffix(backendURL, `/`)
return backendURL
}
func SystemAPIKey() string {
apiKey := Setting(`base`).String(`apiKey`)
return apiKey
}