Skip to content

Commit

Permalink
feat: move cmd dir to core (#7389)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengkunwang223 authored Dec 17, 2024
1 parent a627aa9 commit d1feb50
Show file tree
Hide file tree
Showing 26 changed files with 52 additions and 98 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion backend/router/entry_xpack.go

This file was deleted.

1 change: 0 additions & 1 deletion backend/server/init_xpack.go

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions cmd/server/cmd/version.go → core/cmd/server/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cmd/server/docs/docs.go → core/cmd/server/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25213,4 +25213,4 @@ var SwaggerInfo = &swag.Spec{

func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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")
}
Expand Down Expand Up @@ -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"`
}
File renamed without changes.
4 changes: 2 additions & 2 deletions cmd/server/main.go → core/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes
File renamed without changes.
2 changes: 1 addition & 1 deletion go.mod → core/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/1Panel-dev/1Panel
module github.com/1Panel-dev/1Panel/core

go 1.23

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions core/init/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion core/init/viper/viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion core/middleware/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/views/website/website/create/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d1feb50

Please sign in to comment.