beegoDemo/beego_demo1/main.go
2021-07-14 16:50:45 +08:00

44 lines
1.2 KiB
Go

package main
import (
_ "beego_demo1/routers"
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
_ "github.com/go-sql-driver/mysql"
)
func init() {
/*
1、注册驱动
2、注册数据库连接
*/
root := beego.AppConfig.String("root")
password := beego.AppConfig.String("password")
host := beego.AppConfig.String("host")
port := beego.AppConfig.String("port")
db := beego.AppConfig.String("db")
//"root:123456@tcp(localhost:3306)/beego?charset=utf8"
data_source := root + ":" + password + "@tcp(" + host + ":" + port + ")/" + db + "?charset=utf8"
orm.RegisterDriver("mysql", orm.DRMySQL)
orm.RegisterDataBase("default", "mysql", data_source)
}
func main() {
//设置views路径
//beego.SetViewsPath("front")
port, _ := beego.AppConfig.Int("httpport")
fmt.Printf("%d %T \n", port, port)
username := beego.AppConfig.String("username")
fmt.Printf("%s %T \n", username, username)
root := beego.AppConfig.String("root")
fmt.Printf("%s %T \n", root, root)
//xsrf防护 对post请求起作用
beego.BConfig.WebConfig.EnableXSRF = true
beego.BConfig.WebConfig.XSRFKey = "9029zyjlpydzxzyq9029"
beego.BConfig.WebConfig.XSRFExpire = 3600
//开启sql打印
orm.Debug = true
beego.Run()
}