mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-13 17:24:44 +08:00
feat: move cmd dir to core (#7389)
This commit is contained in:
parent
a627aa9915
commit
d1feb502df
8
.gitignore
vendored
8
.gitignore
vendored
@ -34,10 +34,10 @@ __debug*
|
||||
# Dependency directories
|
||||
/pkg/
|
||||
backend/__debug_bin
|
||||
cmd/server/__debug_bin
|
||||
cmd/server/web/assets
|
||||
cmd/server/web/monacoeditorwork
|
||||
cmd/server/web/index.html
|
||||
core/cmd/server/__debug_bin
|
||||
core/cmd/server/web/assets
|
||||
core/cmd/server/web/monacoeditorwork
|
||||
core/cmd/server/web/index.html
|
||||
frontend/auto-imports.d.ts
|
||||
frontend/components.d.ts
|
||||
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 (
|
||||
"fmt"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/cmd/server/conf"
|
||||
"github.com/1Panel-dev/1Panel/core/configs"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/core/cmd/server/conf"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/spf13/cobra"
|
@ -25213,4 +25213,4 @@ var SwaggerInfo = &swag.Spec{
|
||||
|
||||
func init() {
|
||||
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
|
||||
}
|
||||
}
|
@ -3,76 +3,23 @@ package docs
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"github.com/spf13/afero"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGenerateXlog(t *testing.T) {
|
||||
fset := token.NewFileSet()
|
||||
|
||||
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")
|
||||
func TestSome(t *testing.T) {
|
||||
err := afero.NewOsFs().Rename("/opt/tmp/ceshi", "/opt/tmp/ceshi2")
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("json marshal for new file failed, err: %v", err))
|
||||
}
|
||||
if err := os.WriteFile("x-log.json", newJson, 0640); err != nil {
|
||||
panic(fmt.Sprintf("write new swagger.json failed, err: %v", err))
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateSwaggerDoc(t *testing.T) {
|
||||
workDir := "/usr/songliu/1Panel"
|
||||
swagBin := "/root/go/bin/swag"
|
||||
workDir := "/Users/wangzhengkun/projects/github.com/1Panel-dev/1Panel"
|
||||
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.Dir = workDir
|
||||
@ -129,6 +76,26 @@ func TestGenerateSwaggerDoc(t *testing.T) {
|
||||
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")
|
||||
if err != nil {
|
||||
fmt.Printf("json marshal for new file failed, err: %v", err)
|
||||
@ -144,6 +111,16 @@ func TestGenerateSwaggerDoc(t *testing.T) {
|
||||
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_core")
|
||||
}
|
||||
@ -181,26 +158,3 @@ func init() {
|
||||
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"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/cmd/server/cmd"
|
||||
_ "github.com/1Panel-dev/1Panel/cmd/server/docs"
|
||||
"github.com/1Panel-dev/1Panel/core/cmd/server/cmd"
|
||||
_ "github.com/1Panel-dev/1Panel/core/cmd/server/docs"
|
||||
)
|
||||
|
||||
// @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
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/cmd/server/docs"
|
||||
"github.com/1Panel-dev/1Panel/cmd/server/web"
|
||||
"github.com/1Panel-dev/1Panel/core/cmd/server/docs"
|
||||
"github.com/1Panel-dev/1Panel/core/cmd/server/web"
|
||||
"github.com/1Panel-dev/1Panel/core/global"
|
||||
"github.com/1Panel-dev/1Panel/core/i18n"
|
||||
"github.com/1Panel-dev/1Panel/core/middleware"
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"path"
|
||||
"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/global"
|
||||
"github.com/1Panel-dev/1Panel/core/utils/cmd"
|
||||
|
@ -12,9 +12,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/cmd/server/docs"
|
||||
"github.com/1Panel-dev/1Panel/core/app/model"
|
||||
"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/global"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -646,6 +646,7 @@ const runtimeReq = ref<Runtime.RuntimeReq>({
|
||||
page: 1,
|
||||
pageSize: 100,
|
||||
status: 'running',
|
||||
type: 'php',
|
||||
});
|
||||
const runtimes = ref<Runtime.RuntimeDTO[]>([]);
|
||||
const versionExist = ref(true);
|
||||
@ -789,6 +790,7 @@ const changeRuntime = (runID: number) => {
|
||||
|
||||
const getRuntimes = async () => {
|
||||
try {
|
||||
console.log(runtimeReq.value);
|
||||
const res = await SearchRuntimes(runtimeReq.value);
|
||||
runtimes.value = res.data.items || [];
|
||||
if (runtimes.value.length > 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user