main.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package main
  2. import (
  3. _ "github.com/GoAdminGroup/go-admin/adapter/gin" // web framework adapter
  4. _ "github.com/GoAdminGroup/go-admin/modules/db/drivers/sqlite" // sql driver
  5. _ "github.com/GoAdminGroup/themes/adminlte" // ui theme
  6. "github.com/GoAdminGroup/example/pages"
  7. "github.com/GoAdminGroup/example/tables"
  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/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. template.AddComp(chartjs.NewChart())
  20. //cfg := config.Config{
  21. // Databases: config.DatabaseList{
  22. // "default": {
  23. // Host: "127.0.0.1",
  24. // Port: "3306",
  25. // User: "root",
  26. // Pwd: "root",
  27. // Name: "go-admin",
  28. // MaxIdleCon: 50,
  29. // MaxOpenCon: 150,
  30. // Driver: db.DriverMysql,
  31. // },
  32. // },
  33. // UrlPrefix: "admin",
  34. // IndexUrl: "/",
  35. // Debug: true,
  36. // Language: language.CN,
  37. //}
  38. if err := eng.AddConfigFromJSON("./config.json").
  39. AddGenerators(tables.Generators).
  40. AddGenerator("external", tables.GetExternalTable).
  41. Use(r); err != nil {
  42. panic(err)
  43. }
  44. r.Static("/uploads", "./uploads")
  45. eng.HTML("GET", "/admin", DashboardPage)
  46. eng.HTML("GET", "/admin/form", pages.GetFormContent)
  47. eng.HTML("GET", "/admin/table", pages.GetTableContent)
  48. eng.HTMLFile("GET", "/admin/hello", "./html/hello.tmpl", map[string]interface{}{
  49. "msg": "Hello world",
  50. })
  51. _ = r.Run(":9033")
  52. }