main.go 1.9 KB

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