main.go 1.7 KB

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