liteblog/main.go

42 lines
887 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"encoding/gob"
"github.com/astaxie/beego"
"liteblog/models"
_ "liteblog/routers"
_ "liteblog/models"
"strings"
)
func main() {
initTemplate()
initSession()
beego.Run()
}
func initTemplate() {
_ = beego.AddFuncMap("equrl", func(x, y string) bool {
s1 := strings.Trim(x, "/")
s2 := strings.Trim(y, "/")
return strings.Compare(s1, s2) == 0
})
_ = beego.AddFuncMap("add", func(x, y int) int {
return x + y
})
}
func initSession() {
// beego的session序列号是用gob的方式因此需要将注册models.User
gob.Register(models.User{})
// https://beego.me/docs/mvc/controller/session.md
beego.BConfig.WebConfig.Session.SessionOn = true
beego.BConfig.WebConfig.Session.SessionName = "liteblog-key"
beego.BConfig.WebConfig.Session.SessionProvider = "file"
beego.BConfig.WebConfig.Session.SessionProviderConfig = "data/session"
}