main.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. examplePlugin := example.NewExample()
  30. template.AddComp(chartjs.NewChart())
  31. // you can also add config like:
  32. //
  33. // import "github.com/GoAdminGroup/go-admin/modules/config"
  34. //
  35. // cfg := config.Config{
  36. // Databases: config.DatabaseList{
  37. // "default": {
  38. // Host: "127.0.0.1",
  39. // Port: "3306",
  40. // User: "root",
  41. // Pwd: "root",
  42. // Name: "godmin",
  43. // MaxIdleCon: 50,
  44. // MaxOpenCon: 150,
  45. // Driver: db.DriverMysql,
  46. // },
  47. // },
  48. // UrlPrefix: "admin",
  49. // IndexUrl: "/",
  50. // Debug: true,
  51. // Language: language.CN,
  52. // }
  53. //
  54. // eng.AddConfig(cfg)
  55. if err := eng.AddConfigFromJSON("./config.json").
  56. AddPlugins(adminPlugin, examplePlugin).
  57. Use(r); err != nil {
  58. panic(err)
  59. }
  60. r.Static("/uploads", "./uploads")
  61. // customize your index pages
  62. r.GET("/admin", func(ctx *gin.Context) {
  63. engine.Content(ctx, func(ctx interface{}) (types.Panel, error) {
  64. return DashboardPage()
  65. })
  66. })
  67. _ = r.Run(":9033")
  68. }