main.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "github.com/0xJacky/Nginx-UI/internal/kernal"
  6. "github.com/0xJacky/Nginx-UI/internal/nginx"
  7. "github.com/0xJacky/Nginx-UI/model"
  8. "github.com/0xJacky/Nginx-UI/router"
  9. "github.com/0xJacky/Nginx-UI/settings"
  10. "github.com/jpillora/overseer"
  11. "github.com/uozi-tech/cosy"
  12. "github.com/uozi-tech/cosy/logger"
  13. cSettings "github.com/uozi-tech/cosy/settings"
  14. "time"
  15. )
  16. func Program(confPath string) func(state overseer.State) {
  17. return func(state overseer.State) {
  18. defer logger.Sync()
  19. cosy.RegisterModels(model.GenerateAllModel()...)
  20. cosy.RegisterAsyncFunc(kernal.Boot, router.InitRouter)
  21. if state.Listener != nil {
  22. cosy.SetListener(state.Listener)
  23. cosy.Boot(confPath)
  24. logger.Infof("Nginx configuration directory: %s", nginx.GetConfPath())
  25. }
  26. logger.Info("Server exited")
  27. }
  28. }
  29. func main() {
  30. var confPath string
  31. flag.StringVar(&confPath, "config", "app.ini", "Specify the configuration file")
  32. flag.Parse()
  33. settings.Migrate(confPath)
  34. cSettings.Init(confPath)
  35. overseer.Run(overseer.Config{
  36. Program: Program(confPath),
  37. Address: fmt.Sprintf("%s:%d", cSettings.ServerSettings.Host, cSettings.ServerSettings.Port),
  38. TerminateTimeout: 5 * time.Second,
  39. })
  40. }