init.go 592 B

12345678910111213141516171819202122232425262728293031
  1. package init
  2. import (
  3. "encoding/gob"
  4. "fmt"
  5. _ "github.com/beego/beego/v2/server/web/session/redis"
  6. "nginx-ui/server/config"
  7. "nginx-ui/server/db"
  8. "nginx-ui/server/models"
  9. _ "nginx-ui/server/routers"
  10. "nginx-ui/server/utils"
  11. "os"
  12. )
  13. func ensureIndexHtml() {
  14. if !utils.IsExist("views") {
  15. os.Mkdir("views", 0777)
  16. }
  17. sourceDir := utils.GetStaticDir()
  18. utils.CopyFile(sourceDir+"/index.html", "views/index.html")
  19. }
  20. func init() {
  21. fmt.Printf("-------init---")
  22. gob.Register(models.User{})
  23. db.Init()
  24. config.InitAdmin()
  25. fmt.Println("init success")
  26. ensureRoutes()
  27. ensureIndexHtml()
  28. }