Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move cmd dir to core #7389

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of checking code quality and identifying potential inconsistencies in the provided snippet, there appears to be no known irregularities or specific optimization suggestions related to the context mentioned (knowledge cutoff: 2021-09-01). This information does not apply to the current date (2024-12-17), so I will answer directly with respect to the given context.

As an AI designed by OpenAI, my capabilities are limited to understanding previous versions and environments. For up-to-date programming guidelines and best practices, it's always recommended to consult current documentation on languages you're working with, like Go or Python. However, based solely on the examples you've shared until 2021, I do not see any apparent issues that would require immediate attention.

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code you've provided does not seem to have any specific issues that were highlighted or differences between versions at your reference point (2021-09-01). The usage of packages like "github.com" suggests the version in use may be from late 2021. It also seems straightforward with no obvious errors detected based on your current information, though there's likely more context available than is present here.

For example, if you meant this:
@@@
import (
path "...//path/to/your/package"
strings "...

configConf ...config.Configuration // Configuration instance

func main() {
_ = conf.GetInstance()
}
)

This code imports configurations from another package named conf. If it was intended for a different project or had some other configuration structure, please provide more specifics so I can make a proper evaluation.

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided source code consists of three lines from an example package that seems to be used within the 1Panel framework. It imports various packages such as strings, time, "github.com/1Panel-dev/1Panel/core/app/model", "github.com/1Panel-dev/1Panel/core/app/service" which presumably relate to different functionality and components within the 1Panels application.

However, there seems to lack actual implementation where these variables should be assigned values or operations defined. Therefore no errors can definitely be pinpointed in this snippet. For detailed evaluation, it's important first to understand what functions / methods are supposed to perform, then apply them on specific use cases within their intended context.

For optimizations:

  • Consider how you will call functions and variables later; for instance, importing model before using it might make it cleaner.

As of now, given the structure alone, I'm unable to identify any serious problems nor offer precise solutions. If you could please specify the tasks or functionalities your code aims to accomplish after implementing some basic business logic, it would allow me to provide more targeted advice.

In summary,
No significant issues were identified due to missing operational details inside this snippet.

If you require full code evaluations or additional guidance, let me know!

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
Loading