/
main.go
95 lines (85 loc) · 2.3 KB
/
main.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
package main
import (
"encoding/base64"
"github.com/astaxie/beego"
// "github.com/astaxie/beego/session"
"fmt"
"strings"
"time"
"github.com/ckeyer/goblog/conf"
"github.com/ckeyer/goblog/models"
"github.com/ckeyer/goblog/routers"
)
var (
config *conf.Config
)
// init 初始化
func init() {
var err error
conf.SetFilePath("conf/config.json")
config, err = conf.GetConfig()
if err != nil {
panic(err)
}
}
func main() {
db_init()
server_init()
tpl_init()
routers.Error_init()
beego.Run()
}
func server_init() {
// beego.EnableHttpTLS = true
// beego.HttpsPort = 443
beego.SessionOn = true
beego.SessionGCMaxLifetime = 2
beego.SessionName = "CkeyerSession"
beego.BeegoServerName = "ckeyer Server 1.0"
// beego.HttpCertFile = "/var/www/https/cert.pem"
// beego.HttpKeyFile = "/var/www/https/key.pem"
}
func db_init() {
models.RegistDB()
}
func tpl_init() {
beego.TemplateLeft = "<%"
beego.TemplateRight = "%>"
beego.AddFuncMap("FMT_DATETIME", func(t time.Time) string {
return fmt.Sprintf("%v-%02d-%02d %02d:%02d",
t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute())
})
beego.AddFuncMap("FMT_DATE_MONTH", func(t time.Time) string {
return fmt.Sprintf("%v-%02d", t.Year(), t.Month())
})
// beego.AddFuncMap("STATIC_URL", func() string {
// return beego.AppConfig.String("static_rul")
// })
// beego.AddFuncMap("SITE_URL", func() string {
// return beego.AppConfig.String("site_url")
// })
// beego.AddFuncMap("STATIC_URL_JS", func() string {
// return beego.AppConfig.String("static_url_js_ssl")
// })
// beego.AddFuncMap("STATIC_URL_CSS", func() string {
// return beego.AppConfig.String("static_url_css_ssl")
// })
// beego.AddFuncMap("STATIC_URL_IMG", func() string {
// return beego.AppConfig.String("static_url_img_ssl")
// })
// beego.AddFuncMap("CUSTOM_URL_JS", func() string {
// return beego.AppConfig.String("custom_url_js")
// })
// beego.AddFuncMap("CUSTOM_URL_CSS", func() string {
// return beego.AppConfig.String("custom_url_css")
// })
// beego.AddFuncMap("CUSTOM_URL_IMG", func() string {
// return beego.AppConfig.String("custom_url_img")
// })
beego.AddFuncMap("DECODEBASE64", func(s string) string {
s = strings.Replace(s, "+", "-", -1)
s = strings.Replace(s, "/", "_", -1)
v, _ := base64.URLEncoding.DecodeString(s)
return string(v)
})
}