main.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package main
  2. import (
  3. "io/ioutil"
  4. "log"
  5. "os"
  6. "os/signal"
  7. _ "github.com/GoAdminGroup/go-admin/adapter/gin" // web framework adapter
  8. _ "github.com/GoAdminGroup/go-admin/modules/db/drivers/mysql" // sql driver
  9. _ "github.com/GoAdminGroup/themes/sword" // ui theme
  10. "github.com/GoAdminGroup/go-admin/engine"
  11. "github.com/GoAdminGroup/go-admin/template"
  12. "github.com/GoAdminGroup/go-admin/template/chartjs"
  13. "github.com/gin-gonic/gin"
  14. "goadmin-demo/models"
  15. "goadmin-demo/pages"
  16. "goadmin-demo/tables"
  17. )
  18. func main() {
  19. startServer()
  20. }
  21. func startServer() {
  22. gin.SetMode(gin.ReleaseMode)
  23. gin.DefaultWriter = ioutil.Discard
  24. r := gin.Default()
  25. template.AddComp(chartjs.NewChart())
  26. eng := engine.Default()
  27. if err := eng.AddConfigFromYAML("./config.yml").
  28. AddGenerators(tables.Generators).
  29. Use(r); err != nil {
  30. panic(err)
  31. }
  32. r.Static("/uploads", "./uploads")
  33. eng.HTML("GET", "/admin", pages.GetDashBoard)
  34. eng.HTMLFile("GET", "/admin/hello", "./html/hello.tmpl", map[string]interface{}{
  35. "msg": "Hello world",
  36. })
  37. models.Init(eng.MysqlConnection())
  38. _ = r.Run(":80")
  39. quit := make(chan os.Signal, 1)
  40. signal.Notify(quit, os.Interrupt)
  41. <-quit
  42. log.Print("closing database connection")
  43. eng.MysqlConnection().Close()
  44. }