mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
refactor: migrate to new cosy
This commit is contained in:
parent
6082aef5d5
commit
33a996e777
111 changed files with 1163 additions and 1772 deletions
38
main.go
38
main.go
|
@ -4,31 +4,34 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"github.com/0xJacky/Nginx-UI/internal/kernal"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/router"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jpillora/overseer"
|
||||
"net/http"
|
||||
"github.com/uozi-tech/cosy"
|
||||
"github.com/uozi-tech/cosy/logger"
|
||||
cSettings "github.com/uozi-tech/cosy/settings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Program(state overseer.State) {
|
||||
defer logger.Sync()
|
||||
func Program(confPath string) func(state overseer.State) {
|
||||
return func(state overseer.State) {
|
||||
defer logger.Sync()
|
||||
|
||||
logger.Infof("Nginx configuration directory: %s", nginx.GetConfPath())
|
||||
cosy.RegisterModels(model.GenerateAllModel()...)
|
||||
|
||||
kernal.Boot()
|
||||
cosy.RegisterAsyncFunc(kernal.Boot, router.InitRouter)
|
||||
|
||||
if state.Listener != nil {
|
||||
err := http.Serve(state.Listener, router.InitRouter())
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
if state.Listener != nil {
|
||||
cosy.SetListener(state.Listener)
|
||||
|
||||
cosy.Boot(confPath)
|
||||
|
||||
logger.Infof("Nginx configuration directory: %s", nginx.GetConfPath())
|
||||
}
|
||||
logger.Info("Server exited")
|
||||
}
|
||||
|
||||
logger.Info("Server exited")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -36,13 +39,12 @@ func main() {
|
|||
flag.StringVar(&confPath, "config", "app.ini", "Specify the configuration file")
|
||||
flag.Parse()
|
||||
|
||||
settings.Init(confPath)
|
||||
|
||||
gin.SetMode(settings.ServerSettings.RunMode)
|
||||
settings.Migrate(confPath)
|
||||
cSettings.Init(confPath)
|
||||
|
||||
overseer.Run(overseer.Config{
|
||||
Program: Program,
|
||||
Address: fmt.Sprintf("%s:%s", settings.ServerSettings.HttpHost, settings.ServerSettings.HttpPort),
|
||||
Program: Program(confPath),
|
||||
Address: fmt.Sprintf("%s:%d", cSettings.ServerSettings.Host, cSettings.ServerSettings.Port),
|
||||
TerminateTimeout: 5 * time.Second,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue