forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vars.go
71 lines (55 loc) · 1.4 KB
/
vars.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
package global
import (
"fmt"
"net/http"
"os"
"strings"
assetfs "github.com/elazarl/go-bindata-assetfs"
"github.com/yaoapp/gou"
"github.com/yaoapp/xiang/config"
"github.com/yaoapp/xun/capsule"
)
// VERSION 版本号
const VERSION = "0.6.3"
// DOMAIN 许可域
const DOMAIN = "*.iqka.com"
// AllowHosts 解析后的许可域
var AllowHosts = []string{}
// Conf 配置文件
var Conf config.Config
// FileServer 静态服务
var FileServer http.Handler = http.FileServer(assetFS())
// 初始化配置
func init() {
// 解析许可Host
domains := strings.Split(DOMAIN, "|")
for _, domain := range domains {
if !strings.Contains(domain, ".") {
continue
}
if strings.HasPrefix(domain, "*.") {
domain = strings.TrimPrefix(domain, "*.")
}
AllowHosts = append(AllowHosts, domain)
}
Conf = config.Conf
// 数据库连接
if len(Conf.Database.Primary) > 0 {
capsule.AddConn("primary", "mysql", Conf.Database.Primary[0]).SetAsGlobal()
}
// 加密密钥
gou.LoadCrypt(fmt.Sprintf(`{"key":"%s"}`, Conf.Database.AESKey), "AES")
gou.LoadCrypt(`{}`, "PASSWORD")
// 加载数据
Load(Conf)
}
func assetFS() *assetfs.AssetFS {
assetInfo := func(path string) (os.FileInfo, error) {
return os.Stat(path)
}
for k := range _bintree.Children {
k = "ui"
return &assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: assetInfo, Prefix: k, Fallback: "index.html"}
}
panic("unreachable")
}