main.go 1.8 KB

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