main.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package main
  2. import (
  3. _ "github.com/GoAdminGroup/go-admin/adapter/gin" // adapter
  4. _ "github.com/GoAdminGroup/go-admin/modules/db/drivers/sqlite" // sql driver
  5. _ "github.com/GoAdminGroup/themes/adminlte" // theme
  6. "github.com/GoAdminGroup/example/tables"
  7. "github.com/GoAdminGroup/go-admin/engine"
  8. "github.com/GoAdminGroup/go-admin/plugins/example"
  9. "github.com/GoAdminGroup/go-admin/template"
  10. "github.com/GoAdminGroup/go-admin/template/chartjs"
  11. "github.com/GoAdminGroup/go-admin/template/types"
  12. "github.com/gin-gonic/gin"
  13. "io/ioutil"
  14. )
  15. func main() {
  16. r := gin.Default()
  17. gin.SetMode(gin.ReleaseMode)
  18. gin.DefaultWriter = ioutil.Discard
  19. eng := engine.Default()
  20. // customize a plugin
  21. // 自己定制一个插件👇
  22. examplePlugin := example.NewExample()
  23. template.AddComp(chartjs.NewChart())
  24. // you can also add config like:
  25. // 您也可以像下面这样的方式去引入数据库👇
  26. //
  27. // import "github.com/GoAdminGroup/go-admin/modules/config"
  28. //
  29. // cfg := config.Config{
  30. // Databases: config.DatabaseList{
  31. // "default": {
  32. // Host: "127.0.0.1",
  33. // Port: "3306",
  34. // User: "root",
  35. // Pwd: "root",
  36. // Name: "godmin",
  37. // MaxIdleCon: 50,
  38. // MaxOpenCon: 150,
  39. // Driver: db.DriverMysql,
  40. // },
  41. // },
  42. // UrlPrefix: "admin",
  43. // IndexUrl: "/",
  44. // Debug: true,
  45. // Language: language.CN,
  46. // }
  47. //
  48. // eng.AddConfig(cfg)
  49. if err := eng.AddConfigFromJSON("./config.json").
  50. AddGenerators(tables.Generators).
  51. // add generator, first parameter is the url prefix of table when visit.
  52. // example:
  53. //
  54. // "user" => http://localhost:9033/admin/info/user
  55. //
  56. AddGenerator("user", tables.GetUserTable).
  57. AddGenerator("external", tables.GetExternalTable).
  58. AddPlugins(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. }