main.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package main
  2. import (
  3. _ "github.com/GoAdminGroup/go-admin/adapter/gin"
  4. _ "github.com/GoAdminGroup/go-admin/modules/db/drivers/sqlite"
  5. "github.com/GoAdminGroup/go-admin/template"
  6. "github.com/GoAdminGroup/go-admin/template/chartjs"
  7. _ "github.com/GoAdminGroup/themes/adminlte"
  8. "github.com/GoAdminGroup/go-admin/engine"
  9. "github.com/GoAdminGroup/go-admin/examples/datamodel"
  10. "github.com/GoAdminGroup/go-admin/plugins/admin"
  11. "github.com/GoAdminGroup/go-admin/plugins/example"
  12. "github.com/GoAdminGroup/go-admin/template/types"
  13. "github.com/gin-gonic/gin"
  14. "io/ioutil"
  15. )
  16. func main() {
  17. r := gin.Default()
  18. gin.SetMode(gin.ReleaseMode)
  19. gin.DefaultWriter = ioutil.Discard
  20. eng := engine.Default()
  21. adminPlugin := admin.NewAdmin(datamodel.Generators)
  22. // add generator, first parameter is the url prefix of table when visit.
  23. // example:
  24. //
  25. // "user" => http://localhost:9033/admin/info/user
  26. //
  27. adminPlugin.AddGenerator("user", datamodel.GetUserTable)
  28. // customize a plugin
  29. // 自己定制一个插件👇
  30. examplePlugin := example.NewExample()
  31. template.AddComp(chartjs.NewChart())
  32. // you can also add config like:
  33. // 您也可以像下面这样的方式去引入数据库👇
  34. //
  35. // import "github.com/GoAdminGroup/go-admin/modules/config"
  36. //
  37. // cfg := config.Config{
  38. // Databases: config.DatabaseList{
  39. // "default": {
  40. // Host: "127.0.0.1",
  41. // Port: "3306",
  42. // User: "root",
  43. // Pwd: "root",
  44. // Name: "godmin",
  45. // MaxIdleCon: 50,
  46. // MaxOpenCon: 150,
  47. // Driver: db.DriverMysql,
  48. // },
  49. // },
  50. // UrlPrefix: "admin",
  51. // IndexUrl: "/",
  52. // Debug: true,
  53. // Language: language.CN,
  54. // }
  55. //
  56. // eng.AddConfig(cfg)
  57. if err := eng.AddConfigFromJSON("./config.json").
  58. AddPlugins(adminPlugin, examplePlugin).
  59. Use(r); err != nil {
  60. panic(err)
  61. }
  62. r.Static("/uploads", "./uploads")
  63. // customize your index pages
  64. // 下面这样定制您的首页👇
  65. r.GET("/admin", func(ctx *gin.Context) {
  66. engine.Content(ctx, func(ctx interface{}) (types.Panel, error) {
  67. return DashboardPage()
  68. })
  69. })
  70. _ = r.Run(":9033")
  71. }