4 Star 10 Fork 3

来去如风/RbacManager

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 1.87 KB
一键复制 编辑 原始数据 按行查看 历史
来去如风 提交于 2017-02-04 09:37 . 增加 数据库链接可配置
package main
import (
_ "git.oschina.net/liukexing/RbacManager/models/center"
"git.oschina.net/liukexing/RbacManager/models/flatui"
_ "git.oschina.net/liukexing/RbacManager/routers"
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
//_ "github.com/mattn/go-sqlite3"
)
func main() {
FuncMapInit()
DataBaseInit()
FilterInit()
beego.Run()
}
func FuncMapInit() {
//beego.AddFuncMap("htmlbuild", flatui.Htmlbuild)
//beego.AddFuncMap("themebuild", flatui.Themebuild)
}
func DataBaseInit() {
var dns string
db_type := beego.AppConfig.String("db_type")
db_host := beego.AppConfig.String(db_type + "::db_host")
db_port := beego.AppConfig.String(db_type + "::db_port")
db_user := beego.AppConfig.String(db_type + "::db_user")
db_pass := beego.AppConfig.String(db_type + "::db_pass")
db_name := beego.AppConfig.String(db_type + "::db_name")
db_path := beego.AppConfig.String(db_type + "::db_path")
db_sslmode := beego.AppConfig.String(db_type + "::sslmode")
switch db_type {
case "mysql":
orm.RegisterDriver("mysql", orm.DRMySQL)
dns = fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", db_user, db_pass, db_host, db_port, db_name)
break
case "postgres":
orm.RegisterDriver("postgres", orm.DRPostgres)
dns = fmt.Sprintf("dbname=%s host=%s user=%s password=%s port=%s sslmode=%s", db_name, db_host, db_user, db_pass, db_port, db_sslmode)
case "sqlite3":
orm.RegisterDriver("sqlite3", orm.DRSqlite)
if db_path == "" {
db_path = "./"
}
dns = fmt.Sprintf("%s%s.db", db_path, db_name)
break
default:
beego.Critical("Database driver is not allowed:", db_type)
}
orm.RegisterDataBase("default", db_type, dns)
//orm.RegisterDataBase("default", "mysql", "root:@/herbalifecenter?charset=utf8", 30)
flatui.Syncdb()
}
func FilterInit() {
beego.InsertFilter("/*", beego.BeforeExec, flatui.GetUserAgent)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/liukexing/RbacManager.git
git@gitee.com:liukexing/RbacManager.git
liukexing
RbacManager
RbacManager
master

搜索帮助