mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-12-09 20:05:54 +08:00
feat: move cmd dir to core (#7389)
This commit is contained in:
parent
a627aa9915
commit
d1feb502df
26 changed files with 52 additions and 98 deletions
8
.gitignore
vendored
8
.gitignore
vendored
|
|
@ -34,10 +34,10 @@ __debug*
|
||||||
# Dependency directories
|
# Dependency directories
|
||||||
/pkg/
|
/pkg/
|
||||||
backend/__debug_bin
|
backend/__debug_bin
|
||||||
cmd/server/__debug_bin
|
core/cmd/server/__debug_bin
|
||||||
cmd/server/web/assets
|
core/cmd/server/web/assets
|
||||||
cmd/server/web/monacoeditorwork
|
core/cmd/server/web/monacoeditorwork
|
||||||
cmd/server/web/index.html
|
core/cmd/server/web/index.html
|
||||||
frontend/auto-imports.d.ts
|
frontend/auto-imports.d.ts
|
||||||
frontend/components.d.ts
|
frontend/components.d.ts
|
||||||
frontend/src/xpack
|
frontend/src/xpack
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
/usr/songliu/xpack-backend/other/entry_xpack.go
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
/usr/songliu/xpack-backend/other/init_xpack.go
|
|
||||||
|
|
@ -2,9 +2,9 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/cmd/server/conf"
|
|
||||||
"github.com/1Panel-dev/1Panel/core/configs"
|
"github.com/1Panel-dev/1Panel/core/configs"
|
||||||
|
|
||||||
|
"github.com/1Panel-dev/1Panel/core/cmd/server/conf"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
@ -25213,4 +25213,4 @@ var SwaggerInfo = &swag.Spec{
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
|
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
|
||||||
}
|
}
|
||||||
|
|
@ -3,76 +3,23 @@ package docs
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/ast"
|
"github.com/spf13/afero"
|
||||||
"go/parser"
|
|
||||||
"go/token"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGenerateXlog(t *testing.T) {
|
func TestSome(t *testing.T) {
|
||||||
fset := token.NewFileSet()
|
err := afero.NewOsFs().Rename("/opt/tmp/ceshi", "/opt/tmp/ceshi2")
|
||||||
|
|
||||||
apiDirs := []string{"../../../agent/app/api/v2", "../../../core/app/api/v2", "../../../agent/xpack/app/api/v2", "../../../core/xpack/app/api/v2"}
|
|
||||||
|
|
||||||
xlogMap := make(map[string]operationJson)
|
|
||||||
for _, dir := range apiDirs {
|
|
||||||
if err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if info.IsDir() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
fileItem, err := parser.ParseFile(fset, path, nil, parser.ParseComments)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, decl := range fileItem.Decls {
|
|
||||||
switch d := decl.(type) {
|
|
||||||
case *ast.FuncDecl:
|
|
||||||
if d.Doc != nil {
|
|
||||||
routerContent := ""
|
|
||||||
logContent := ""
|
|
||||||
for _, comment := range d.Doc.List {
|
|
||||||
if strings.HasPrefix(comment.Text, "// @Router") {
|
|
||||||
routerContent = replaceStr(comment.Text, "// @Router", "[post]", "[get]", " ")
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(comment.Text, "// @x-panel-log") {
|
|
||||||
logContent = replaceStr(comment.Text, "// @x-panel-log", " ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(routerContent) != 0 && len(logContent) != 0 {
|
|
||||||
var item operationJson
|
|
||||||
if err := json.Unmarshal([]byte(logContent), &item); err != nil {
|
|
||||||
panic(fmt.Sprintf("json unamrshal failed, err: %v", err))
|
|
||||||
}
|
|
||||||
xlogMap[routerContent] = item
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
newJson, err := json.MarshalIndent(xlogMap, "", "\t")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("json marshal for new file failed, err: %v", err))
|
fmt.Println(err)
|
||||||
}
|
|
||||||
if err := os.WriteFile("x-log.json", newJson, 0640); err != nil {
|
|
||||||
panic(fmt.Sprintf("write new swagger.json failed, err: %v", err))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenerateSwaggerDoc(t *testing.T) {
|
func TestGenerateSwaggerDoc(t *testing.T) {
|
||||||
workDir := "/usr/songliu/1Panel"
|
workDir := "/Users/wangzhengkun/projects/github.com/1Panel-dev/1Panel"
|
||||||
swagBin := "/root/go/bin/swag"
|
swagBin := "/Users/wangzhengkun/go/bin/swag"
|
||||||
|
|
||||||
cmd1 := exec.Command(swagBin, "init", "-o", workDir+"/cmd/server/docs/docs_agent", "-d", workDir+"/agent", "-g", "./cmd/server/main.go")
|
cmd1 := exec.Command(swagBin, "init", "-o", workDir+"/cmd/server/docs/docs_agent", "-d", workDir+"/agent", "-g", "./cmd/server/main.go")
|
||||||
cmd1.Dir = workDir
|
cmd1.Dir = workDir
|
||||||
|
|
@ -129,6 +76,26 @@ func TestGenerateSwaggerDoc(t *testing.T) {
|
||||||
newSwagger.Paths[key] = val
|
newSwagger.Paths[key] = val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newXLog := make(map[string]interface{})
|
||||||
|
for key, val := range newSwagger.Paths {
|
||||||
|
methodMap, isMethodMap := val.(map[string]interface{})
|
||||||
|
if !isMethodMap {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
dataMap, hasPost := methodMap["post"]
|
||||||
|
if !hasPost {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
data, isDataMap := dataMap.(map[string]interface{})
|
||||||
|
if !isDataMap {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
xLog, hasXLog := data["x-panel-log"]
|
||||||
|
if !hasXLog {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
newXLog[key] = xLog
|
||||||
|
}
|
||||||
newJson, err := json.MarshalIndent(newSwagger, "", "\t")
|
newJson, err := json.MarshalIndent(newSwagger, "", "\t")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("json marshal for new file failed, err: %v", err)
|
fmt.Printf("json marshal for new file failed, err: %v", err)
|
||||||
|
|
@ -144,6 +111,16 @@ func TestGenerateSwaggerDoc(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newXLogFile, err := json.MarshalIndent(newXLog, "", "\t")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("json marshal for new x-log file failed, err: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := os.WriteFile("x-log.json", newXLogFile, 0640); err != nil {
|
||||||
|
fmt.Printf("write new x-log.json failed, err: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
_ = os.RemoveAll(workDir + "/cmd/server/docs/docs_agent")
|
_ = os.RemoveAll(workDir + "/cmd/server/docs/docs_agent")
|
||||||
_ = os.RemoveAll(workDir + "/cmd/server/docs/docs_core")
|
_ = os.RemoveAll(workDir + "/cmd/server/docs/docs_core")
|
||||||
}
|
}
|
||||||
|
|
@ -181,26 +158,3 @@ func init() {
|
||||||
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
|
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func replaceStr(val string, rep ...string) string {
|
|
||||||
for _, item := range rep {
|
|
||||||
val = strings.ReplaceAll(val, item, "")
|
|
||||||
}
|
|
||||||
return val
|
|
||||||
}
|
|
||||||
|
|
||||||
type operationJson struct {
|
|
||||||
BodyKeys []string `json:"bodyKeys"`
|
|
||||||
ParamKeys []string `json:"paramKeys"`
|
|
||||||
BeforeFunctions []functionInfo `json:"beforeFunctions"`
|
|
||||||
FormatZH string `json:"formatZH"`
|
|
||||||
FormatEN string `json:"formatEN"`
|
|
||||||
}
|
|
||||||
type functionInfo struct {
|
|
||||||
InputColumn string `json:"input_column"`
|
|
||||||
InputValue string `json:"input_value"`
|
|
||||||
IsList bool `json:"isList"`
|
|
||||||
DB string `json:"db"`
|
|
||||||
OutputColumn string `json:"output_column"`
|
|
||||||
OutputValue string `json:"output_value"`
|
|
||||||
}
|
|
||||||
|
|
@ -6,8 +6,8 @@ import (
|
||||||
|
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/cmd/server/cmd"
|
"github.com/1Panel-dev/1Panel/core/cmd/server/cmd"
|
||||||
_ "github.com/1Panel-dev/1Panel/cmd/server/docs"
|
_ "github.com/1Panel-dev/1Panel/core/cmd/server/docs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// @title 1Panel
|
// @title 1Panel
|
||||||
|
Before Width: | Height: | Size: 9.1 KiB After Width: | Height: | Size: 9.1 KiB |
|
|
@ -1,4 +1,4 @@
|
||||||
module github.com/1Panel-dev/1Panel
|
module github.com/1Panel-dev/1Panel/core
|
||||||
|
|
||||||
go 1.23
|
go 1.23
|
||||||
|
|
||||||
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/cmd/server/docs"
|
"github.com/1Panel-dev/1Panel/core/cmd/server/docs"
|
||||||
"github.com/1Panel-dev/1Panel/cmd/server/web"
|
"github.com/1Panel-dev/1Panel/core/cmd/server/web"
|
||||||
"github.com/1Panel-dev/1Panel/core/global"
|
"github.com/1Panel-dev/1Panel/core/global"
|
||||||
"github.com/1Panel-dev/1Panel/core/i18n"
|
"github.com/1Panel-dev/1Panel/core/i18n"
|
||||||
"github.com/1Panel-dev/1Panel/core/middleware"
|
"github.com/1Panel-dev/1Panel/core/middleware"
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/cmd/server/conf"
|
"github.com/1Panel-dev/1Panel/core/cmd/server/conf"
|
||||||
"github.com/1Panel-dev/1Panel/core/configs"
|
"github.com/1Panel-dev/1Panel/core/configs"
|
||||||
"github.com/1Panel-dev/1Panel/core/global"
|
"github.com/1Panel-dev/1Panel/core/global"
|
||||||
"github.com/1Panel-dev/1Panel/core/utils/cmd"
|
"github.com/1Panel-dev/1Panel/core/utils/cmd"
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/cmd/server/docs"
|
|
||||||
"github.com/1Panel-dev/1Panel/core/app/model"
|
"github.com/1Panel-dev/1Panel/core/app/model"
|
||||||
"github.com/1Panel-dev/1Panel/core/app/service"
|
"github.com/1Panel-dev/1Panel/core/app/service"
|
||||||
|
"github.com/1Panel-dev/1Panel/core/cmd/server/docs"
|
||||||
"github.com/1Panel-dev/1Panel/core/constant"
|
"github.com/1Panel-dev/1Panel/core/constant"
|
||||||
"github.com/1Panel-dev/1Panel/core/global"
|
"github.com/1Panel-dev/1Panel/core/global"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
|
||||||
|
|
@ -646,6 +646,7 @@ const runtimeReq = ref<Runtime.RuntimeReq>({
|
||||||
page: 1,
|
page: 1,
|
||||||
pageSize: 100,
|
pageSize: 100,
|
||||||
status: 'running',
|
status: 'running',
|
||||||
|
type: 'php',
|
||||||
});
|
});
|
||||||
const runtimes = ref<Runtime.RuntimeDTO[]>([]);
|
const runtimes = ref<Runtime.RuntimeDTO[]>([]);
|
||||||
const versionExist = ref(true);
|
const versionExist = ref(true);
|
||||||
|
|
@ -789,6 +790,7 @@ const changeRuntime = (runID: number) => {
|
||||||
|
|
||||||
const getRuntimes = async () => {
|
const getRuntimes = async () => {
|
||||||
try {
|
try {
|
||||||
|
console.log(runtimeReq.value);
|
||||||
const res = await SearchRuntimes(runtimeReq.value);
|
const res = await SearchRuntimes(runtimeReq.value);
|
||||||
runtimes.value = res.data.items || [];
|
runtimes.value = res.data.items || [];
|
||||||
if (runtimes.value.length > 0) {
|
if (runtimes.value.length > 0) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue