mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 06:47:20 +08:00
feat: cli 路由支持
This commit is contained in:
@@ -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/
|
||||
|
||||
@@ -17,34 +17,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
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()
|
||||
}
|
||||
|
||||
@@ -30,5 +30,5 @@ import "github.com/TheTNB/panel/internal/bootstrap"
|
||||
|
||||
// @BasePath /api
|
||||
func main() {
|
||||
bootstrap.Boot()
|
||||
bootstrap.BootWeb()
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
# config
|
||||
|
||||
config 目录存放应用使用的各种配置文件。
|
||||
|
||||
不喜欢 toml 格式?你可以随意调整 `init.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()
|
||||
}
|
||||
|
||||
26
internal/bootstrap/cli.go
Normal file
26
internal/bootstrap/cli.go
Normal file
@@ -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))
|
||||
}
|
||||
}
|
||||
19
internal/route/cli.go
Normal file
19
internal/route/cli.go
Normal file
@@ -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,
|
||||
},
|
||||
}
|
||||
}
|
||||
15
internal/service/cli.go
Normal file
15
internal/service/cli.go
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user