Skip to content

Commit

Permalink
refactor: 重写子命令实现
Browse files Browse the repository at this point in the history
降低对外部库的依赖数量,减少代码量,提高可读性
  • Loading branch information
rehiy committed Nov 26, 2023
1 parent 51c1d76 commit 24a2bc9
Show file tree
Hide file tree
Showing 26 changed files with 405 additions and 703 deletions.
4 changes: 2 additions & 2 deletions api/alibaba/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package alibaba
import (
"github.com/gin-gonic/gin"
"github.com/opentdp/go-helper/alibaba"
"github.com/spf13/cast"
"github.com/opentdp/go-helper/strutil"

"tdp-cloud/model/vendor"
)

func apiProxy(c *gin.Context) {

rq := &vendor.FetchParam{
Id: cast.ToUint(c.Param("id")),
Id: strutil.ToUint(c.Param("id")),
UserId: c.GetUint("UserId"),
StoreKey: c.GetString("AppKey"),
}
Expand Down
4 changes: 2 additions & 2 deletions api/cloudflare/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package cloudflare
import (
"github.com/gin-gonic/gin"
"github.com/opentdp/go-helper/cloudflare"
"github.com/spf13/cast"
"github.com/opentdp/go-helper/strutil"

"tdp-cloud/model/vendor"
)

func apiProxy(c *gin.Context) {

rq := &vendor.FetchParam{
Id: cast.ToUint(c.Param("id")),
Id: strutil.ToUint(c.Param("id")),
UserId: c.GetUint("UserId"),
StoreKey: c.GetString("AppKey"),
}
Expand Down
4 changes: 2 additions & 2 deletions api/tencent/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"net/http"

"github.com/gin-gonic/gin"
"github.com/opentdp/go-helper/strutil"
"github.com/opentdp/go-helper/tencent"
"github.com/spf13/cast"

"tdp-cloud/cmd/args"
"tdp-cloud/model/vendor"
Expand All @@ -15,7 +15,7 @@ import (
func apiProxy(c *gin.Context) {

rq := &vendor.FetchParam{
Id: cast.ToUint(c.Param("id")),
Id: strutil.ToUint(c.Param("id")),
UserId: c.GetUint("UserId"),
StoreKey: c.GetString("AppKey"),
}
Expand Down
4 changes: 2 additions & 2 deletions api/terminal/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package terminal

import (
"github.com/gin-gonic/gin"
"github.com/opentdp/go-helper/strutil"
"github.com/opentdp/go-helper/webssh"
"github.com/spf13/cast"
"golang.org/x/net/websocket"

"tdp-cloud/model/keypair"
Expand All @@ -20,7 +20,7 @@ func ssh(c *gin.Context) {
return
}

if id := cast.ToUint(c.Param("id")); id > 0 {
if id := strutil.ToUint(c.Param("id")); id > 0 {
kp, err := keypair.Fetch(&keypair.FetchParam{
Id: id,
UserId: c.GetUint("UserId"),
Expand Down
4 changes: 2 additions & 2 deletions api/workhub/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package workhub
import (
"github.com/gin-gonic/gin"
"github.com/opentdp/go-helper/command"
"github.com/spf13/cast"
"github.com/opentdp/go-helper/strutil"
"golang.org/x/net/websocket"

"tdp-cloud/model/user"
Expand Down Expand Up @@ -84,7 +84,7 @@ func register(c *gin.Context) {
}

c.Set("UserId", ur.Id)
c.Set("MachineId", cast.ToUint(c.Param("mid")))
c.Set("MachineId", strutil.ToUint(c.Param("mid")))

// 创建 Worker 会话

Expand Down
11 changes: 7 additions & 4 deletions cmd/args/build.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package args

// 版本信息

const Version = "0.14.5"
const BuildVersion = "231125"

const AppName = "TDP CLoud"
const AppSummary = "土豆片云面板"
// 更新地址

const UpdateUrl = "https://get.opentdp.org/update/cloud"

const ReadmeText = AppSummary + `
// 应用描述

可以跨平台部署的云资源管理面板
const AppName = "TDP CLoud"
const AppSummary = "可以跨平台部署的云资源管理面板"

const ReadmeText = `
TDP Website: https://www.opentdp.org
Open Source: https://github.com/opentdp`
44 changes: 0 additions & 44 deletions cmd/args/config.go

This file was deleted.

68 changes: 0 additions & 68 deletions cmd/args/factory.go

This file was deleted.

77 changes: 77 additions & 0 deletions cmd/args/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package args

import (
"embed"

"github.com/opentdp/go-helper/strutil"
)

// 调试模式

var Debug bool

// 嵌入文件

var Efs *embed.FS

// 数据存储

type IDataset struct {
Dir string
Secret string
}

var Dataset = IDataset{
Dir: "var",
Secret: strutil.Rand(32),
}

// 日志参数

type ILogger struct {
Dir string
Level string
Target string
}

var Logger = ILogger{
Dir: ".",
Level: "info",
Target: "stdout",
}

// 数据库参数

type IDatabase struct {
Type string
Host string
User string
Passwd string
Name string
Option string
}

var Database = IDatabase{
Type: "sqlite",
Name: "server.db",
}

// 主节点参数

type IServer struct {
Listen string
JwtKey string
}

var Server = IServer{
Listen: ":7800",
JwtKey: strutil.Rand(32),
}

// 子节点参数

type IWorker struct {
Remote string
}

var Worker = IWorker{}
16 changes: 0 additions & 16 deletions cmd/args/runtime.go

This file was deleted.

17 changes: 0 additions & 17 deletions cmd/initd/dataset.go

This file was deleted.

26 changes: 0 additions & 26 deletions cmd/initd/logger.go

This file was deleted.

Loading

0 comments on commit 24a2bc9

Please sign in to comment.