139 Star 1.3K Fork 432

go-admin/go-admin

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 2.69 KB
一键复制 编辑 原始数据 按行查看 历史
honkui 提交于 2022-08-23 22:56 +08:00 . feat(db): add db param
package main
import (
"io/ioutil"
"log"
"os"
"os/signal"
"time"
_ "github.com/GoAdminGroup/go-admin/adapter/gin"
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/mysql"
_ "github.com/GoAdminGroup/themes/sword"
"github.com/GoAdminGroup/go-admin/engine"
"github.com/GoAdminGroup/go-admin/examples/datamodel"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/modules/language"
"github.com/GoAdminGroup/go-admin/plugins/example"
"github.com/GoAdminGroup/go-admin/template"
"github.com/GoAdminGroup/go-admin/template/chartjs"
"github.com/GoAdminGroup/themes/adminlte"
"github.com/gin-gonic/gin"
)
func main() {
gin.SetMode(gin.ReleaseMode)
gin.DefaultWriter = ioutil.Discard
r := gin.New()
e := engine.Default()
cfg := config.Config{
Env: config.EnvLocal,
Databases: config.DatabaseList{
"default": {
Host: "127.0.0.1",
Port: "3306",
User: "root",
Pwd: "root",
Name: "godmin",
MaxIdleConns: 50,
MaxOpenConns: 150,
ConnMaxLifetime: time.Hour,
Driver: config.DriverMysql,
//Driver: config.DriverSqlite,
//File: "../datamodel/admin.db",
},
},
UrlPrefix: "admin",
Store: config.Store{
Path: "./uploads",
Prefix: "uploads",
},
Language: language.CN,
IndexUrl: "/",
Debug: true,
AccessAssetsLogOff: true,
Animation: config.PageAnimation{
Type: "fadeInUp",
},
ColorScheme: adminlte.ColorschemeSkinBlack,
BootstrapFilePath: "./../datamodel/bootstrap.go",
}
template.AddComp(chartjs.NewChart())
// customize a plugin
examplePlugin := example.NewExample()
// load from golang.Plugin
//
// examplePlugin := plugins.LoadFromPlugin("../datamodel/example.so")
// customize the login page
// example: https://github.com/GoAdminGroup/demo.go-admin.cn/blob/master/main.go#L39
//
// template.AddComp("login", datamodel.LoginPage)
// load config from json file
//
// e.AddConfigFromJSON("../datamodel/config.json")
if err := e.AddConfig(&cfg).
AddGenerators(datamodel.Generators).
// add generator, first parameter is the url prefix of table when visit.
// example:
//
// "user" => http://localhost:9033/admin/info/user
//
AddGenerator("user", datamodel.GetUserTable).
AddDisplayFilterXssJsFilter().
AddPlugins(examplePlugin).
Use(r); err != nil {
panic(err)
}
r.Static("/uploads", "./uploads")
// customize your pages
e.HTML("GET", "/admin", datamodel.GetContent)
go func() {
_ = r.Run(":9033")
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
<-quit
log.Print("closing database connection")
e.MysqlConnection().Close()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/go-admin/go-admin.git
git@gitee.com:go-admin/go-admin.git
go-admin
go-admin
go-admin
master

搜索帮助