feat: new command line options

This commit is contained in:
Hintay 2025-02-03 00:19:02 +09:00
parent 4e6b2daf0d
commit 4239a89d66
No known key found for this signature in database
GPG key ID: 120FC7FF121F2F2D
4 changed files with 53 additions and 8 deletions

1
go.mod
View file

@ -37,6 +37,7 @@ require (
github.com/tufanbarisyildirim/gonginx v0.0.0-20250120210832-12a9c7ae0c8a github.com/tufanbarisyildirim/gonginx v0.0.0-20250120210832-12a9c7ae0c8a
github.com/uozi-tech/cosy v1.14.3 github.com/uozi-tech/cosy v1.14.3
github.com/uozi-tech/cosy-driver-sqlite v0.2.0 github.com/uozi-tech/cosy-driver-sqlite v0.2.0
github.com/urfave/cli/v3 v3.0.0-beta1
go.uber.org/zap v1.27.0 go.uber.org/zap v1.27.0
golang.org/x/crypto v0.32.0 golang.org/x/crypto v0.32.0
golang.org/x/net v0.34.0 golang.org/x/net v0.34.0

2
go.sum
View file

@ -1782,6 +1782,8 @@ github.com/uozi-tech/cosy-driver-postgres v0.2.1/go.mod h1:eAy1A89yHbAEfjkhNAifa
github.com/uozi-tech/cosy-driver-sqlite v0.2.0 h1:eTpIMyGoFUK4JcaiKfJHD5AyiM6vtCwN98c7Bz5n25o= github.com/uozi-tech/cosy-driver-sqlite v0.2.0 h1:eTpIMyGoFUK4JcaiKfJHD5AyiM6vtCwN98c7Bz5n25o=
github.com/uozi-tech/cosy-driver-sqlite v0.2.0/go.mod h1:87a6mzn5IuEtIR4z7U4Ey8eKLGfNEOSkv7kPQlbNQgM= github.com/uozi-tech/cosy-driver-sqlite v0.2.0/go.mod h1:87a6mzn5IuEtIR4z7U4Ey8eKLGfNEOSkv7kPQlbNQgM=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/urfave/cli/v3 v3.0.0-beta1 h1:6DTaaUarcM0wX7qj5Hcvs+5Dm3dyUTBbEwIWAjcw9Zg=
github.com/urfave/cli/v3 v3.0.0-beta1/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y=
github.com/vinyldns/go-vinyldns v0.9.16 h1:GZJStDkcCk1F1AcRc64LuuMh+ENL8pHA0CVd4ulRMcQ= github.com/vinyldns/go-vinyldns v0.9.16 h1:GZJStDkcCk1F1AcRc64LuuMh+ENL8pHA0CVd4ulRMcQ=
github.com/vinyldns/go-vinyldns v0.9.16/go.mod h1:5qIJOdmzAnatKjurI+Tl4uTus7GJKJxb+zitufjHs3Q= github.com/vinyldns/go-vinyldns v0.9.16/go.mod h1:5qIJOdmzAnatKjurI+Tl4uTus7GJKJxb+zitufjHs3Q=
github.com/volcengine/volc-sdk-golang v1.0.194 h1:3o0INQzdtYJWvdGrtX02booCqPL5TsWSq2W1Ur7Bzlo= github.com/volcengine/volc-sdk-golang v1.0.194 h1:3o0INQzdtYJWvdGrtX02booCqPL5TsWSq2W1Ur7Bzlo=

43
internal/cmd/main.go Normal file
View file

@ -0,0 +1,43 @@
package cmd
import (
"context"
"log"
"os"
"github.com/urfave/cli/v3"
)
func NewAppCmd() *cli.Command {
serve := false
cmd := &cli.Command{
Name: "nginx-ui",
Usage: "Yet another Nginx Web UI",
Commands: []*cli.Command{
{
Name: "serve",
Usage: "Start the Nginx-UI server",
Action: func(ctx context.Context, command *cli.Command) error {
serve = true
return nil
},
},
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Value: "app.ini",
Usage: "configuration file path",
},
},
DefaultCommand: "serve",
}
if err := cmd.Run(context.Background(), os.Args); err != nil {
log.Fatal(err)
} else if !serve {
os.Exit(0)
}
return cmd
}

15
main.go
View file

@ -1,22 +1,23 @@
package main package main
import ( import (
"flag" "errors"
"fmt" "fmt"
"net/http"
"time"
"github.com/0xJacky/Nginx-UI/internal/cmd"
"github.com/0xJacky/Nginx-UI/internal/kernel" "github.com/0xJacky/Nginx-UI/internal/kernel"
"github.com/0xJacky/Nginx-UI/model" "github.com/0xJacky/Nginx-UI/model"
"github.com/0xJacky/Nginx-UI/router" "github.com/0xJacky/Nginx-UI/router"
"github.com/0xJacky/Nginx-UI/settings" "github.com/0xJacky/Nginx-UI/settings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/jpillora/overseer" "github.com/jpillora/overseer"
"errors"
"github.com/uozi-tech/cosy" "github.com/uozi-tech/cosy"
cKernel "github.com/uozi-tech/cosy/kernel" cKernel "github.com/uozi-tech/cosy/kernel"
"github.com/uozi-tech/cosy/logger" "github.com/uozi-tech/cosy/logger"
cRouter "github.com/uozi-tech/cosy/router" cRouter "github.com/uozi-tech/cosy/router"
cSettings "github.com/uozi-tech/cosy/settings" cSettings "github.com/uozi-tech/cosy/settings"
"net/http"
"time"
) )
func Program(confPath string) func(state overseer.State) { func Program(confPath string) func(state overseer.State) {
@ -58,12 +59,10 @@ func Program(confPath string) func(state overseer.State) {
} }
func main() { func main() {
var confPath string appCmd := cmd.NewAppCmd()
flag.StringVar(&confPath, "config", "app.ini", "Specify the configuration file")
flag.Parse()
confPath := appCmd.String("config")
settings.Init(confPath) settings.Init(confPath)
overseer.Run(overseer.Config{ overseer.Run(overseer.Config{
Program: Program(confPath), Program: Program(confPath),
Address: fmt.Sprintf("%s:%d", cSettings.ServerSettings.Host, cSettings.ServerSettings.Port), Address: fmt.Sprintf("%s:%d", cSettings.ServerSettings.Host, cSettings.ServerSettings.Port),