2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 06:47:20 +08:00

feat: 初始化cli路由

This commit is contained in:
耗子
2024-09-27 03:08:56 +08:00
parent 881eb7bfb1
commit 4054c788f3
5 changed files with 241 additions and 179 deletions

3
go.mod
View File

@@ -39,7 +39,6 @@ require (
github.com/stretchr/testify v1.9.0
github.com/swaggo/http-swagger/v2 v2.0.2
github.com/swaggo/swag v1.16.3
github.com/urfave/cli/v2 v2.27.4
github.com/urfave/cli/v3 v3.0.0-alpha9
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.27.0
@@ -57,7 +56,6 @@ require (
github.com/bodgit/windows v1.0.0 // indirect
github.com/connesc/cipherio v0.2.1 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
@@ -105,7 +103,6 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/swaggo/files/v2 v2.0.0 // indirect
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.597 // indirect
github.com/therootcompany/xz v1.0.1 // indirect

6
go.sum
View File

@@ -46,8 +46,6 @@ github.com/connesc/cipherio v0.2.1 h1:FGtpTPMbKNNWByNrr9aEBtaJtXjqOzkIXNYJp6OEyc
github.com/connesc/cipherio v0.2.1/go.mod h1:ukY0MWJDFnJEbXMQtOcn2VmTpRfzcTz4OoVrWGGJZcA=
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@@ -278,8 +276,6 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qq
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd/go.mod h1:hPqNNc0+uJM6H+SuU8sEs5K5IQeKccPqeSjfgcKGgPk=
github.com/sethvargo/go-limiter v1.0.0 h1:JqW13eWEMn0VFv86OKn8wiYJY/m250WoXdrjRV0kLe4=
github.com/sethvargo/go-limiter v1.0.0/go.mod h1:01b6tW25Ap+MeLYBuD4aHunMrJoNO5PVUFdS9rac3II=
@@ -321,8 +317,6 @@ github.com/tklauser/numcpus v0.8.0/go.mod h1:ZJZlAY+dmR4eut8epnzf0u/VwodKmryxR8t
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/urfave/cli/v2 v2.27.4 h1:o1owoI+02Eb+K107p27wEX9Bb8eqIoZCfLXloLUSWJ8=
github.com/urfave/cli/v2 v2.27.4/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ=
github.com/urfave/cli/v3 v3.0.0-alpha9 h1:P0RMy5fQm1AslQS+XCmy9UknDXctOmG/q/FZkUFnJSo=
github.com/urfave/cli/v3 v3.0.0-alpha9/go.mod h1:0kK/RUFHyh+yIKSfWxwheGndfnrvYSmYFVeKCh03ZUc=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=

View File

@@ -1,90 +1,57 @@
package route
import (
"context"
"fmt"
"github.com/urfave/cli/v3"
"github.com/TheTNB/panel/internal/service"
)
func Cli() []*cli.Command {
//cliService := service.NewCliService()
cliService := service.NewCliService()
return []*cli.Command{
{
Name: "restart",
Usage: "重启面板服务",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
Name: "restart",
Usage: "重启面板服务",
Action: cliService.Restart,
},
{
Name: "stop",
Usage: "停止面板服务",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
Name: "stop",
Usage: "停止面板服务",
Action: cliService.Stop,
},
{
Name: "start",
Usage: "启动面板服务",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
Name: "start",
Usage: "启动面板服务",
Action: cliService.Start,
},
{
Name: "update",
Usage: "升级面板主程序",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
Name: "update",
Usage: "升级面板",
Action: cliService.Update,
},
{
Name: "update-cli",
Usage: "升级面板命令行工具",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
},
{
Name: "info",
Usage: "输出面板基本信息",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
Name: "info",
Usage: "输出面板基本信息",
Action: cliService.Info,
},
{
Name: "user",
Usage: "操作面板用户",
Commands: []*cli.Command{
{
Name: "list",
Usage: "列出所有用户",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
Name: "list",
Usage: "列出所有用户",
Action: cliService.UserList,
},
{
Name: "username",
Usage: "修改用户名",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
Name: "username",
Usage: "修改用户名",
Action: cliService.UserName,
},
{
Name: "password",
Usage: "修改用户密码",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
Name: "password",
Usage: "修改用户密码",
Action: cliService.UserPassword,
},
},
},
@@ -93,20 +60,14 @@ func Cli() []*cli.Command {
Usage: "操作面板HTTPS",
Commands: []*cli.Command{
{
Name: "on",
Usage: "开启HTTPS",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
Name: "on",
Usage: "开启HTTPS",
Action: cliService.HTTPSOn,
},
{
Name: "off",
Usage: "关闭HTTPS",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
Name: "off",
Usage: "关闭HTTPS",
Action: cliService.HTTPSOff,
},
},
},
@@ -115,67 +76,46 @@ func Cli() []*cli.Command {
Usage: "操作面板访问入口",
Commands: []*cli.Command{
{
Name: "on",
Usage: "开启访问入口",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
Name: "on",
Usage: "开启访问入口",
Action: cliService.EntranceOn,
},
{
Name: "off",
Usage: "关闭访问入口",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
Name: "off",
Usage: "关闭访问入口",
Action: cliService.EntranceOff,
},
},
},
{
Name: "port",
Usage: "修改面板端口",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
Name: "port",
Usage: "修改面板端口",
Action: cliService.Port,
},
{
Name: "website",
Usage: "网站管理",
Commands: []*cli.Command{
{
Name: "add",
Usage: "创建新站点",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("new task template: ", cmd.Args().First())
return nil
},
Name: "create",
Usage: "创建新站点",
Action: cliService.WebsiteCreate,
},
{
Name: "remove",
Usage: "移除站点",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("removed task template: ", cmd.Args().First())
return nil
},
Name: "remove",
Usage: "移除站点",
Action: cliService.WebsiteRemove,
},
{
Name: "delete",
Usage: "删除站点(包括站点目录、同名数据库)",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("removed task template: ", cmd.Args().First())
return nil
},
Name: "delete",
Usage: "删除站点(包括站点目录、同名数据库)",
Action: cliService.WebsiteDelete,
},
{
Name: "write",
Usage: "写入网站数据(仅限指导下使用)",
Hidden: true,
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("removed task template: ", cmd.Args().First())
return nil
},
Action: cliService.WebsiteWrite,
},
},
},
@@ -184,28 +124,19 @@ func Cli() []*cli.Command {
Usage: "备份数据",
Commands: []*cli.Command{
{
Name: "website",
Usage: "备份网站",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("new task template: ", cmd.Args().First())
return nil
},
Name: "website",
Usage: "备份网站",
Action: cliService.BackupWebsite,
},
{
Name: "database",
Usage: "备份数据库",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("removed task template: ", cmd.Args().First())
return nil
},
Name: "database",
Usage: "备份数据库",
Action: cliService.BackupDatabase,
},
{
Name: "panel",
Usage: "备份面板",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("removed task template: ", cmd.Args().First())
return nil
},
Name: "panel",
Usage: "备份面板",
Action: cliService.BackupPanel,
},
},
},
@@ -214,68 +145,63 @@ func Cli() []*cli.Command {
Usage: "日志切割",
Commands: []*cli.Command{
{
Name: "website",
Usage: "网站",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("new task template: ", cmd.Args().First())
return nil
},
Name: "website",
Usage: "网站",
Action: cliService.CutoffWebsite,
},
},
},
{
Name: "writeApp",
Usage: "添加面板应用标记(仅限指导下使用)",
Hidden: true,
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
Name: "app",
Usage: "应用管理",
Commands: []*cli.Command{
{
Name: "install",
Usage: "安装应用",
Action: cliService.AppInstall,
},
{
Name: "uninstall",
Usage: "卸载应用",
Action: cliService.AppUnInstall,
},
{
Name: "write",
Usage: "添加面板应用标记(仅限指导下使用)",
Hidden: true,
Action: cliService.AppWrite,
},
{
Name: "remove",
Usage: "移除面板应用标记(仅限指导下使用)",
Hidden: true,
Action: cliService.AppRemove,
},
},
},
{
Name: "removeApp",
Usage: "移除面板应用标记(仅限指导下使用)",
Hidden: true,
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
},
{
Name: "cleanTask",
Name: "clearTask",
Usage: "清理面板任务队列(仅限指导下使用)",
Hidden: true,
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
Action: cliService.ClearTask,
},
{
Name: "writeSetting",
Usage: "写入面板设置(仅限指导下使用)",
Hidden: true,
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
Action: cliService.WriteSetting,
},
{
Name: "removeSetting",
Usage: "移除面板设置(仅限指导下使用)",
Hidden: true,
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("completed task: ", cmd.Args().First())
return nil
},
Action: cliService.RemoveSetting,
},
{
Name: "init",
Usage: "初始化面板(仅限指导下使用)",
Hidden: true,
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("added task: ", cmd.Args().First())
return nil
},
Action: cliService.Init,
},
}
}

View File

@@ -1,6 +1,12 @@
package service
import "github.com/urfave/cli/v2"
import (
"context"
"github.com/urfave/cli/v3"
"github.com/TheTNB/panel/pkg/systemctl"
)
type CliService struct {
}
@@ -9,7 +15,144 @@ func NewCliService() *CliService {
return &CliService{}
}
func (s *CliService) Test(c *cli.Context) error {
func (s *CliService) Restart(ctx context.Context, cmd *cli.Command) error {
return systemctl.Restart("panel")
}
func (s *CliService) Stop(ctx context.Context, cmd *cli.Command) error {
return systemctl.Stop("panel")
}
func (s *CliService) Start(ctx context.Context, cmd *cli.Command) error {
return systemctl.Start("panel")
}
func (s *CliService) Update(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) Info(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) UserList(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) UserName(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) UserPassword(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) HTTPSOn(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) HTTPSOff(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) EntranceOn(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) EntranceOff(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) Port(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) WebsiteCreate(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) WebsiteRemove(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) WebsiteDelete(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) WebsiteWrite(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) BackupWebsite(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) BackupDatabase(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) BackupPanel(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) CutoffWebsite(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) AppInstall(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) AppUnInstall(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) AppWrite(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) AppRemove(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) ClearTask(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) WriteSetting(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) RemoveSetting(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}
func (s *CliService) Init(ctx context.Context, cmd *cli.Command) error {
println("Hello, World!")
return nil
}

View File

@@ -1,5 +1,7 @@
//go:build !linux
// 这个文件只是为了在 Windows 下能编译通过,实际上并没有任何卵用
package service
import (