main.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/template"
  9. "github.com/GoAdminGroup/go-admin/template/chartjs"
  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. template.AddComp(chartjs.NewChart())
  19. // you can also add config like:
  20. // 您也可以像下面这样的方式去引入数据库👇
  21. //
  22. // import "github.com/GoAdminGroup/go-admin/modules/config"
  23. //
  24. //cfg := config.Config{
  25. // Databases: config.DatabaseList{
  26. // "default": {
  27. // Host: "127.0.0.1",
  28. // Port: "3306",
  29. // User: "root",
  30. // Pwd: "root",
  31. // Name: "go-admin-demo",
  32. // MaxIdleCon: 50,
  33. // MaxOpenCon: 150,
  34. // Driver: db.DriverMysql,
  35. // },
  36. // },
  37. // UrlPrefix: "admin",
  38. // IndexUrl: "/",
  39. // Debug: true,
  40. // Language: language.CN,
  41. //}
  42. //
  43. // eng.AddConfig(cfg)
  44. if err := eng.AddConfigFromJSON("./config.json").
  45. AddGenerators(tables.Generators).
  46. // add generator, first parameter is the url prefix of table when visit.
  47. // example:
  48. //
  49. // "user" => http://localhost:9033/admin/info/user
  50. //
  51. // AddGenerator("user", tables.GetUserTable).
  52. AddGenerator("external", tables.GetExternalTable).
  53. Use(r); err != nil {
  54. panic(err)
  55. }
  56. r.Static("/uploads", "./uploads")
  57. // customize your index pages
  58. // 下面这样定制您的首页👇
  59. eng.HTML("GET", "/admin", DashboardPage)
  60. _ = r.Run(":9033")
  61. }