diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 96200371..4f9724e4 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,9 +1,9 @@ project_name: panel builds: - - id: panel + - id: web main: ./cmd/web - binary: panel + binary: web env: - CGO_ENABLED=0 goos: @@ -47,11 +47,8 @@ archives: strip_binary_directory: true files: - LICENSE - - docs/* - storage/* - - lang/* - - scripts/* - - panel-example.conf + - config/* gitlab_urls: api: https://git.haozi.net/api/v4/ diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 9ec50a63..d7fafbfa 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -17,34 +17,9 @@ along with this program. If not, see . package main import ( - "fmt" - "log" - "os" - - "github.com/urfave/cli/v2" + "github.com/TheTNB/panel/internal/bootstrap" ) func main() { - app := &cli.App{ - Name: "panel", - HelpName: "耗子面板", - Usage: "命令行工具", - UsageText: "panel [global options] command [command options] [arguments...]", - HideVersion: true, - Commands: []*cli.Command{ - { - Name: "test", - Aliases: []string{"t"}, - Usage: "print a test message", - Action: func(c *cli.Context) error { - fmt.Println("Hello, World!") - return nil - }, - }, - }, - } - - if err := app.Run(os.Args); err != nil { - log.Fatal(err) - } + bootstrap.BootCli() } diff --git a/cmd/web/main.go b/cmd/web/main.go index 173d5af3..e40edec5 100644 --- a/cmd/web/main.go +++ b/cmd/web/main.go @@ -30,5 +30,5 @@ import "github.com/TheTNB/panel/internal/bootstrap" // @BasePath /api func main() { - bootstrap.Boot() + bootstrap.BootWeb() } diff --git a/config/README.md b/config/README.md deleted file mode 100644 index 20f1eba1..00000000 --- a/config/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# config - -config 目录存放应用使用的各种配置文件。 - -不喜欢 toml 格式?你可以随意调整 `init.go` 以兼容你想要配置格式。 \ No newline at end of file diff --git a/internal/bootstrap/app.go b/internal/bootstrap/app.go index 9669966c..90f696c6 100644 --- a/internal/bootstrap/app.go +++ b/internal/bootstrap/app.go @@ -4,7 +4,7 @@ import ( "runtime/debug" ) -func Boot() { +func boot() { debug.SetGCPercent(10) debug.SetMemoryLimit(64 << 20) @@ -12,6 +12,10 @@ func Boot() { initGlobal() initOrm() runMigrate() +} + +func BootWeb() { + boot() initValidator() initSession() initQueue() @@ -19,3 +23,8 @@ func Boot() { select {} } + +func BootCli() { + boot() + initCli() +} diff --git a/internal/bootstrap/cli.go b/internal/bootstrap/cli.go new file mode 100644 index 00000000..9d634690 --- /dev/null +++ b/internal/bootstrap/cli.go @@ -0,0 +1,26 @@ +package bootstrap + +import ( + "fmt" + "os" + + "github.com/urfave/cli/v2" + + "github.com/TheTNB/panel/internal/panel" + "github.com/TheTNB/panel/internal/route" +) + +func initCli() { + app := &cli.App{ + Name: "panel-cli", + HelpName: fmt.Sprintf("耗子面板 %s", panel.Version), + Usage: "命令行工具", + UsageText: "panel-cli [global options] command [command options] [arguments...]", + HideVersion: true, + Commands: route.Cli(), + } + + if err := app.Run(os.Args); err != nil { + panic(fmt.Sprintf("failed to run cli: %v", err)) + } +} diff --git a/internal/route/cli.go b/internal/route/cli.go new file mode 100644 index 00000000..febbd9d5 --- /dev/null +++ b/internal/route/cli.go @@ -0,0 +1,19 @@ +package route + +import ( + "github.com/urfave/cli/v2" + + "github.com/TheTNB/panel/internal/service" +) + +func Cli() []*cli.Command { + cliService := service.NewCliService() + return []*cli.Command{ + { + Name: "test", + Aliases: []string{"t"}, + Usage: "print a test message", + Action: cliService.Test, + }, + } +} diff --git a/internal/service/cli.go b/internal/service/cli.go new file mode 100644 index 00000000..ca283c44 --- /dev/null +++ b/internal/service/cli.go @@ -0,0 +1,15 @@ +package service + +import "github.com/urfave/cli/v2" + +type CliService struct { +} + +func NewCliService() *CliService { + return &CliService{} +} + +func (s *CliService) Test(c *cli.Context) error { + println("Hello, World!") + return nil +}