| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package main
- import (
- _ "github.com/GoAdminGroup/go-admin/adapter/gin"
- "github.com/GoAdminGroup/go-admin/engine"
- "github.com/GoAdminGroup/go-admin/examples/datamodel"
- "github.com/GoAdminGroup/go-admin/plugins/admin"
- "github.com/GoAdminGroup/go-admin/plugins/example"
- "github.com/GoAdminGroup/go-admin/template/types"
- _ "github.com/GoAdminGroup/themes/adminlte"
- "github.com/gin-gonic/gin"
- "io/ioutil"
- )
- func main() {
- r := gin.Default()
- gin.SetMode(gin.ReleaseMode)
- gin.DefaultWriter = ioutil.Discard
- eng := engine.Default()
- adminPlugin := admin.NewAdmin(datamodel.Generators)
- // add generator, first parameter is the url prefix of table when visit.
- // example:
- //
- // "user" => http://localhost:9033/admin/info/user
- //
- adminPlugin.AddGenerator("user", datamodel.GetUserTable)
- // customize a plugin
- examplePlugin := example.NewExample()
- // you can also add config like:
- //
- // import "github.com/GoAdminGroup/go-admin/modules/config""
- //
- // cfg := config.Config{
- // Databases: config.DatabaseList{
- // "default": {
- // Host: "127.0.0.1",
- // Port: "3306",
- // User: "root",
- // Pwd: "root",
- // Name: "godmin",
- // MaxIdleCon: 50,
- // MaxOpenCon: 150,
- // Driver: db.DriverMysql,
- // },
- // },
- // UrlPrefix: "admin",
- // IndexUrl: "/",
- // Debug: true,
- // Language: language.CN,
- // }
- //
- // eng.AddConfig(cfg)
- if err := eng.AddConfigFromJson("./config.json").
- AddPlugins(adminPlugin, examplePlugin).
- Use(r); err != nil {
- panic(err)
- }
- r.Static("/uploads", "./uploads")
- // customize your index pages
- r.GET("/admin", func(ctx *gin.Context) {
- engine.Content(ctx, func(ctx interface{}) (types.Panel, error) {
- return datamodel.GetContent()
- })
- })
- _ = r.Run(":9033")
- }
|