From c921f24ce0055e75ac98aa7c41b664cdfc531c68 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 12 Oct 2022 20:31:09 +0800 Subject: [PATCH 1/3] [add] fs support & golang version 1.9.2 --- .github/workflows/pr-test.yml | 6 +-- .github/workflows/release-linux.yml | 2 +- .github/workflows/release-macos.yml | 2 +- .github/workflows/unit-test.yml | 2 +- cmd/root.go | 1 + cmd/start.go | 5 +++ config/types.go | 17 ++++---- engine/load.go | 7 ++++ fs/fs.go | 45 +++++++++++++++++++++ fs/fs_test.go | 30 ++++++++++++++ go.mod | 30 +++++++------- go.sum | 7 +++- main_test.go | 2 +- system/process.go | 61 ++++++++++++----------------- system/process_test.go | 21 ++++------ system/system.go | 2 +- xfs/process.go | 1 + xfs/process_test.go | 2 + xfs/xfs.go | 4 +- xfs/xfs_test.go | 2 + 20 files changed, 165 insertions(+), 84 deletions(-) create mode 100644 fs/fs.go create mode 100644 fs/fs_test.go diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml index 3a4cbdd0..5ed4626a 100644 --- a/.github/workflows/pr-test.yml +++ b/.github/workflows/pr-test.yml @@ -50,7 +50,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: [1.18.2] + go: [1.19.2] db: [MySQL8.0, MySQL5.7, SQLite3] redis: [4, 5, 6] mongo: ["6.0"] @@ -99,7 +99,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, issue_number: issue_number, - body: 'Thank you for the PR! The ${{ matrix.db }} test workflow is running, the results of the run will be commented later.' + body: 'Thank you for the PR! The db: ${{ matrix.db }} redis: ${{ matrix.redis }} mongo: ${{ matrix.mongo }} test workflow is running, the results of the run will be commented later.' }); - name: Setup Cache @@ -255,5 +255,5 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, issue_number: issue_number, - body: '✨DONE✨ ${{ matrix.db }} passed.' + body: '✨DONE✨ db: ${{ matrix.db }} redis: ${{ matrix.redis }} mongo: ${{ matrix.mongo }} passed.' }); diff --git a/.github/workflows/release-linux.yml b/.github/workflows/release-linux.yml index 27b26651..5c29c9b2 100644 --- a/.github/workflows/release-linux.yml +++ b/.github/workflows/release-linux.yml @@ -14,7 +14,7 @@ jobs: release: strategy: matrix: - go: [1.18.2] + go: [1.19.2] runs-on: "ubuntu-latest" steps: - name: Arm Build diff --git a/.github/workflows/release-macos.yml b/.github/workflows/release-macos.yml index 3eaf009a..65a78dcd 100644 --- a/.github/workflows/release-macos.yml +++ b/.github/workflows/release-macos.yml @@ -14,7 +14,7 @@ jobs: release: strategy: matrix: - go: [1.18.2] + go: [1.19.2] runs-on: "macos-11" steps: - name: Install coscmd diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 15a60aef..29545dec 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -54,7 +54,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: [1.18.2] + go: [1.19.2] db: [MySQL8.0, MySQL5.7, SQLite3] redis: [4, 5, 6] mongo: ["6.0"] diff --git a/cmd/root.go b/cmd/root.go index eb095106..84d63d31 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -32,6 +32,7 @@ var langs = map[string]string{ "API": " API接口", "API List": "API列表", "Root": "应用目录", + "Data": "数据目录", "Frontend": "前台地址", "Dashboard": "管理后台", "Not enough arguments": "参数错误: 缺少参数", diff --git a/cmd/start.go b/cmd/start.go index 1de96fe4..98e5d30f 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -20,6 +20,7 @@ import ( "github.com/yaoapp/kun/log" "github.com/yaoapp/yao/config" "github.com/yaoapp/yao/engine" + "github.com/yaoapp/yao/fs" "github.com/yaoapp/yao/service" "github.com/yaoapp/yao/share" ) @@ -60,6 +61,8 @@ var startCmd = &cobra.Command{ host = "127.0.0.1" } + dataRoot, _ := fs.Root(config.Conf) + fmt.Println(color.WhiteString("\n---------------------------------")) fmt.Println(color.WhiteString(share.App.Name), color.WhiteString(share.App.Version), mode) fmt.Println(color.WhiteString("---------------------------------")) @@ -71,12 +74,14 @@ var startCmd = &cobra.Command{ if share.App.XGen == "1.0" { root, _ := adminRoot() fmt.Println(color.WhiteString(L(" XGen")), color.GreenString(" 1.0")) + fmt.Println(color.WhiteString(L("Data")), color.GreenString(" %s", dataRoot)) fmt.Println(color.WhiteString(L("Frontend")), color.GreenString(" http://%s%s/", host, port)) fmt.Println(color.WhiteString(L("Dashboard")), color.GreenString(" http://%s%s%slogin/admin", host, port, root)) fmt.Println(color.WhiteString(L("API")), color.GreenString(" http://%s%s/api", host, port)) fmt.Println(color.WhiteString(L("Listening")), color.GreenString(" %s:%d", config.Conf.Host, config.Conf.Port)) } else { + fmt.Println(color.WhiteString(L("Data")), color.GreenString(" %s", dataRoot)) fmt.Println(color.WhiteString(L("Frontend")), color.GreenString(" http://%s%s/", host, port)) fmt.Println(color.WhiteString(L("Dashboard")), color.GreenString(" http://%s%s/xiang/login/admin", host, port)) fmt.Println(color.WhiteString(L("API")), color.GreenString(" http://%s%s/api", host, port)) diff --git a/config/types.go b/config/types.go index ebd3ed22..e97de955 100644 --- a/config/types.go +++ b/config/types.go @@ -2,14 +2,15 @@ package config // Config 象传应用引擎配置 type Config struct { - Mode string `json:"mode,omitempty" env:"YAO_ENV" envDefault:"production"` // 象传引擎启动模式 production/development - Root string `json:"root,omitempty" env:"YAO_ROOT" envDefault:"."` // 应用根目录 - Host string `json:"host,omitempty" env:"YAO_HOST" envDefault:"0.0.0.0"` // 服务监听地址 - Port int `json:"port,omitempty" env:"YAO_PORT" envDefault:"5099"` // 服务监听端口 - Cert string `json:"cert,omitempty" env:"YAO_CERT"` // HTTPS 证书文件地址 - Key string `json:"key,omitempty" env:"YAO_KEY"` // HTTPS 证书密钥地址 - Log string `json:"log,omitempty" env:"YAO_LOG"` // 服务日志地址 - LogMode string `json:"log_mode,omitempty" env:"YAO_LOG_MODE" envDefault:"TEXT"` // 服务日志模式 JSON|TEXT + Mode string `json:"mode,omitempty" env:"YAO_ENV" envDefault:"production"` // 象传引擎启动模式 production/development + Root string `json:"root,omitempty" env:"YAO_ROOT" envDefault:"."` // 应用根目录 + DataRoot string `json:"data_root,omitempty" env:"YAO_DATA_ROOT" envDefault:""` // DATA PATH + Host string `json:"host,omitempty" env:"YAO_HOST" envDefault:"0.0.0.0"` // 服务监听地址 + Port int `json:"port,omitempty" env:"YAO_PORT" envDefault:"5099"` // 服务监听端口 + Cert string `json:"cert,omitempty" env:"YAO_CERT"` // HTTPS 证书文件地址 + Key string `json:"key,omitempty" env:"YAO_KEY"` // HTTPS 证书密钥地址 + Log string `json:"log,omitempty" env:"YAO_LOG"` // 服务日志地址 + LogMode string `json:"log_mode,omitempty" env:"YAO_LOG_MODE" envDefault:"TEXT"` // 服务日志模式 JSON|TEXT // Session string `json:"session,omitempty" env:"YAO_SESSION" envDefault:"memory"` // 用户会话模式 memory|redis|database JWTSecret string `json:"jwt_secret,omitempty" env:"YAO_JWT_SECRET"` // JWT 密钥 DB DBConfig `json:"db,omitempty"` // 数据库配置 diff --git a/engine/load.go b/engine/load.go index 9fc757d7..ab3c2355 100644 --- a/engine/load.go +++ b/engine/load.go @@ -16,6 +16,7 @@ import ( "github.com/yaoapp/yao/config" "github.com/yaoapp/yao/connector" "github.com/yaoapp/yao/flow" + "github.com/yaoapp/yao/fs" "github.com/yaoapp/yao/importer" "github.com/yaoapp/yao/model" "github.com/yaoapp/yao/page" @@ -57,6 +58,12 @@ func Load(cfg config.Config) (err error) { printErr(cfg.Mode, "Connector", err) } + // Load FileSystem + err = fs.Load(cfg) + if err != nil { + printErr(cfg.Mode, "FileSystem", err) + } + // 第二步: 建立数据库 & 会话连接 share.DBConnect(cfg.DB) // 创建数据库连接 // share.SessionConnect(cfg.Session) // 创建会话服务器链接 diff --git a/fs/fs.go b/fs/fs.go new file mode 100644 index 00000000..30de20b9 --- /dev/null +++ b/fs/fs.go @@ -0,0 +1,45 @@ +package fs + +import ( + "os" + "path/filepath" + + "github.com/yaoapp/gou/fs" + "github.com/yaoapp/gou/fs/system" + "github.com/yaoapp/yao/config" +) + +// Load system fs +func Load(cfg config.Config) error { + + root, err := Root(cfg) + if err != nil { + return err + } + + if _, err := os.Stat(root); os.IsNotExist(err) { + err := os.MkdirAll(root, os.ModePerm) + if err != nil { + return err + } + } + + fs.Register("system", system.New(root)) + fs.Register("binary", system.New(root)) // next + return nil +} + +// Root return data root +func Root(cfg config.Config) (string, error) { + root := cfg.DataRoot + if root == "" { + root = filepath.Join(cfg.Root, "data") + } + + root, err := filepath.Abs(root) + if err != nil { + return "", err + } + + return root, nil +} diff --git a/fs/fs_test.go b/fs/fs_test.go new file mode 100644 index 00000000..cb630182 --- /dev/null +++ b/fs/fs_test.go @@ -0,0 +1,30 @@ +package fs + +import ( + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/yaoapp/gou/fs" + "github.com/yaoapp/yao/config" +) + +func TestLoad(t *testing.T) { + Load(config.Conf) + + data := fs.MustGet("system") + size, err := fs.WriteFile(data, "test.file", []byte("Hi"), 0644) + assert.Nil(t, err) + assert.Equal(t, 2, size) + + root, err := Root(config.Conf) + assert.Nil(t, err) + + info, err := os.Stat(filepath.Join(root, "test.file")) + assert.Nil(t, err) + assert.Equal(t, int64(2), info.Size()) + + err = fs.Remove(data, "test.file") + assert.Nil(t, err) +} diff --git a/go.mod b/go.mod index b4040537..5c501bc0 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/yaoapp/yao -go 1.18 +go 1.19 require ( github.com/aliyun/alibaba-cloud-sdk-go v1.61.1286 @@ -23,25 +23,13 @@ require ( golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d ) -require ( - github.com/golang/snappy v0.0.1 // indirect - github.com/klauspost/compress v1.13.6 // indirect - github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect - github.com/pkg/errors v0.9.1 // indirect - github.com/xdg-go/pbkdf2 v1.0.0 // indirect - github.com/xdg-go/scram v1.1.1 // indirect - github.com/xdg-go/stringprep v1.0.3 // indirect - github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect - go.mongodb.org/mongo-driver v1.10.2 // indirect - golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect -) - require ( github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2 // indirect github.com/blang/semver/v4 v4.0.0 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/gabriel-vasile/mimetype v1.4.1 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-errors/errors v1.4.2 // indirect github.com/go-playground/locales v0.13.0 // indirect @@ -51,6 +39,7 @@ require ( github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect github.com/golang/protobuf v1.5.2 // indirect + github.com/golang/snappy v0.0.1 // indirect github.com/google/uuid v1.3.0 github.com/gorilla/websocket v1.5.0 // indirect github.com/hashicorp/go-hclog v1.2.0 // indirect @@ -60,6 +49,7 @@ require ( github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect github.com/jmoiron/sqlx v1.3.4 // indirect + github.com/klauspost/compress v1.13.6 // indirect github.com/leodido/go-urn v1.2.0 // indirect github.com/lib/pq v1.10.4 // indirect github.com/mattn/go-colorable v0.1.12 // indirect @@ -70,7 +60,9 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect + github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect github.com/oklog/run v1.1.0 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/richardlehane/mscfb v1.0.3 // indirect github.com/richardlehane/msoleps v1.0.1 // indirect @@ -87,10 +79,16 @@ require ( github.com/tidwall/rtred v0.1.2 // indirect github.com/tidwall/tinyqueue v0.1.1 // indirect github.com/ugorji/go/codec v1.1.7 // indirect + github.com/xdg-go/pbkdf2 v1.0.0 // indirect + github.com/xdg-go/scram v1.1.1 // indirect + github.com/xdg-go/stringprep v1.0.3 // indirect github.com/xuri/efp v0.0.0-20210322160811-ab561f5b45e3 // indirect + github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect + go.mongodb.org/mongo-driver v1.10.2 // indirect golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect golang.org/x/mod v0.4.2 // indirect - golang.org/x/net v0.0.0-20220526153639-5463443f8c37 // indirect + golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect + golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/tools v0.1.7 // indirect @@ -101,7 +99,7 @@ require ( gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/ini.v1 v1.62.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.1 + gopkg.in/yaml.v3 v3.0.1 rogchap.com/v8go v0.7.0 // indirect ) diff --git a/go.sum b/go.sum index 5e464535..6805c07b 100644 --- a/go.sum +++ b/go.sum @@ -92,6 +92,8 @@ github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYF github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= +github.com/gabriel-vasile/mimetype v1.4.1 h1:TRWk7se+TOjCYgRth7+1/OYLNiRNIotknkFtf/dnN7Q= +github.com/gabriel-vasile/mimetype v1.4.1/go.mod h1:05Vi0w3Y9c/lNvJOdmIwvrrAhX3rYhfQQCaf9VJcv7M= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= @@ -500,8 +502,8 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220526153639-5463443f8c37 h1:lUkvobShwKsOesNfWWlCS5q7fnbG1MEliIzwu886fn8= -golang.org/x/net v0.0.0-20220526153639-5463443f8c37/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e h1:TsQ7F31D3bUCLeqPT0u+yjp1guoArKaNKmCr22PYgTQ= +golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -580,6 +582,7 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/main_test.go b/main_test.go index 8a00a058..5d30f841 100644 --- a/main_test.go +++ b/main_test.go @@ -31,7 +31,7 @@ func TestCommandMigrate(t *testing.T) { oldArgs := os.Args defer func() { os.Args = oldArgs }() - os.Args = append(os.Args, "migrate") + os.Args = append(os.Args, "migrate", "--reset", "--force") assert.NotPanics(t, func() { main() }) diff --git a/system/process.go b/system/process.go index 555de4e5..c1155c60 100644 --- a/system/process.go +++ b/system/process.go @@ -1,42 +1,33 @@ package system -import ( - "fmt" - "os/exec" - "strings" +// func init() { +// // gou.RegisterProcessHandler("yao.system.Exec", processExec) +// } - "github.com/yaoapp/gou" - "github.com/yaoapp/kun/exception" -) +// // processExec execute the system command +// func processExec(process *gou.Process) interface{} { +// process.ValidateArgNums(1) +// cmd := process.ArgsString(0) -func init() { - gou.RegisterProcessHandler("yao.system.Exec", processExec) -} +// _, err := exec.LookPath(cmd) +// if err != nil { +// exception.New("command %s not found: %s", 400, cmd, err.Error()).Throw() +// return nil +// } -// processExec execute the system command -func processExec(process *gou.Process) interface{} { - process.ValidateArgNums(1) - cmd := process.ArgsString(0) +// args := []string{} +// for i, arg := range process.Args { +// if i == 0 { +// continue +// } +// args = append(args, fmt.Sprintf("%v", arg)) +// } - _, err := exec.LookPath(cmd) - if err != nil { - exception.New("command %s not found: %s", 400, cmd, err.Error()).Throw() - return nil - } +// res, err := exec.Command(cmd, args...).Output() +// if err != nil { +// exception.New("command %s error: %s", 500, cmd, err.Error()).Throw() +// return nil +// } - args := []string{} - for i, arg := range process.Args { - if i == 0 { - continue - } - args = append(args, fmt.Sprintf("%v", arg)) - } - - res, err := exec.Command(cmd, args...).Output() - if err != nil { - exception.New("command %s error: %s", 500, cmd, err.Error()).Throw() - return nil - } - - return strings.TrimRight(string(res), "\n") -} +// return strings.TrimRight(string(res), "\n") +// } diff --git a/system/process_test.go b/system/process_test.go index 054fd6d0..cb0bfbe9 100644 --- a/system/process_test.go +++ b/system/process_test.go @@ -1,16 +1,9 @@ package system -import ( - "testing" - - "github.com/stretchr/testify/assert" - "github.com/yaoapp/gou" -) - -func TestProcessReturn(t *testing.T) { - output, err := gou.NewProcess("yao.system.Exec", "echo", "hello").Exec() - if err != nil { - t.Fatal(err) - } - assert.Equal(t, "hello", output) -} +// func TestProcessReturn(t *testing.T) { +// output, err := gou.NewProcess("yao.system.Exec", "echo", "hello").Exec() +// if err != nil { +// t.Fatal(err) +// } +// assert.Equal(t, "hello", output) +// } diff --git a/system/system.go b/system/system.go index 61e66e43..bfd256e1 100644 --- a/system/system.go +++ b/system/system.go @@ -1,4 +1,4 @@ package system // Exec call system command -func Exec(cmd string, args ...string) {} +// func Exec(cmd string, args ...string) {} diff --git a/xfs/process.go b/xfs/process.go index 401b67a1..a2baf54f 100644 --- a/xfs/process.go +++ b/xfs/process.go @@ -21,6 +21,7 @@ import ( "github.com/yaoapp/yao/share" ) +// DEPRECATED func init() { // 注册处理器 gou.RegisterProcessHandler("xiang.fs.Upload", processUpload) diff --git a/xfs/process_test.go b/xfs/process_test.go index 7e18f0f4..415c6cd1 100644 --- a/xfs/process_test.go +++ b/xfs/process_test.go @@ -7,6 +7,8 @@ import ( "github.com/yaoapp/yao/share" ) +// DEPRECATED + func init() { share.App = share.AppInfo{ Storage: share.AppStorage{ diff --git a/xfs/xfs.go b/xfs/xfs.go index b3dcf0f6..6dbea5b3 100644 --- a/xfs/xfs.go +++ b/xfs/xfs.go @@ -19,6 +19,8 @@ import ( "github.com/yaoapp/yao/config" ) +// DEPRECATED + // Stor 文件系统实例 var Stor Xfs @@ -209,7 +211,7 @@ func (xfs *Xfs) GetTempDir(subPath string) string { return afero.GetTempDir(xfs.Fs, subPath) } -//MustTempDir 创建临时文件夹 +// MustTempDir 创建临时文件夹 func (xfs *Xfs) MustTempDir(dirname string, prefix string) string { name, err := xfs.TempDir(dirname, prefix) if err != nil { diff --git a/xfs/xfs_test.go b/xfs/xfs_test.go index e063cc61..c21a279a 100644 --- a/xfs/xfs_test.go +++ b/xfs/xfs_test.go @@ -7,6 +7,8 @@ import ( "github.com/stretchr/testify/assert" ) +// DEPRECATED + func TestOSFsMustMkdirAll(t *testing.T) { // fs := New(config.Conf.Source) fs := New(os.Getenv("YAO_DEV")) From bf950a34f67f0ed2eb44c0c3a55429d478029f9b Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 12 Oct 2022 20:35:57 +0800 Subject: [PATCH 2/3] [fix] fmt code --- data/bindata.go | 12 +++++++----- helper/array.go | 20 ++++++++++++-------- workflow/process.go | 40 ++++++++++++++++++++++++++++++---------- 3 files changed, 49 insertions(+), 23 deletions(-) diff --git a/data/bindata.go b/data/bindata.go index 5f210034..ca218563 100644 --- a/data/bindata.go +++ b/data/bindata.go @@ -1057,11 +1057,13 @@ var _bindata = map[string]func() (*asset, error){ // directory embedded in the file by go-bindata. // For example if you run go-bindata on data/... and data contains the // following hierarchy: -// data/ -// foo.txt -// img/ -// a.png -// b.png +// +// data/ +// foo.txt +// img/ +// a.png +// b.png +// // then AssetDir("data") would return []string{"foo.txt", "img"} // AssetDir("data/img") would return []string{"a.png", "b.png"} // AssetDir("foo.txt") and AssetDir("notexist") would return an error diff --git a/helper/array.go b/helper/array.go index c8bc2653..ebc29ef9 100644 --- a/helper/array.go +++ b/helper/array.go @@ -67,15 +67,19 @@ func ArraySplit(records []map[string]interface{}) ([]string, [][]interface{}) { } // ArrayPluck 将多个数据记录集合,合并为一个数据记录集合 -// columns: ["城市", "行业", "计费"] -// pluck: { -// "行业":{"key":"city", "value":"数量", "items":[{"city":"北京", "数量":32},{"city":"上海", "数量":20}]}, -// "计费":{"key":"city", "value":"计费种类", "items":[{"city":"北京", "计费种类":6},{"city":"西安", "计费种类":3}]}, -// } +// +// columns: ["城市", "行业", "计费"] +// pluck: { +// "行业":{"key":"city", "value":"数量", "items":[{"city":"北京", "数量":32},{"city":"上海", "数量":20}]}, +// "计费":{"key":"city", "value":"计费种类", "items":[{"city":"北京", "计费种类":6},{"city":"西安", "计费种类":3}]}, +// } +// // return: [ -// {"城市":"北京", "行业":32, "计费":6}, -// {"城市":"上海", "行业":20, "计费":null}, -// {"城市":"西安", "行业":null, "计费":6} +// +// {"城市":"北京", "行业":32, "计费":6}, +// {"城市":"上海", "行业":20, "计费":null}, +// {"城市":"西安", "行业":null, "计费":6} +// // ] func ArrayPluck(columns []string, pluck map[string]interface{}) []map[string]interface{} { if len(columns) < 2 { diff --git a/workflow/process.go b/workflow/process.go index 13420905..25db1c76 100644 --- a/workflow/process.go +++ b/workflow/process.go @@ -30,7 +30,9 @@ func init() { } // ProcessFind xiang.workflow.Find 读取工作流 -// args: [工作流名称*, 工作流ID*] +// +// args: [工作流名称*, 工作流ID*] +// // return: map[string]interface{} 工作流数据记录 func ProcessFind(process *gou.Process) interface{} { process.ValidateArgNums(2) @@ -39,7 +41,9 @@ func ProcessFind(process *gou.Process) interface{} { } // ProcessOpen xiang.workflow.Open 读取工作流 -// args: [工作流名称*, 当前用户ID*, 关联数据ID*] +// +// args: [工作流名称*, 当前用户ID*, 关联数据ID*] +// // return: map[string]interface{} 工作流数据记录 func ProcessOpen(process *gou.Process) interface{} { process.ValidateArgNums(3) @@ -48,7 +52,9 @@ func ProcessOpen(process *gou.Process) interface{} { } // ProcessSetting xiang.workflow.Setting 读取工作流配置 -// args: [工作流名称*, 当前用户ID*, 关联数据ID*] +// +// args: [工作流名称*, 当前用户ID*, 关联数据ID*] +// // return: map[string]interface{} 工作流配置 func ProcessSetting(process *gou.Process) interface{} { process.ValidateArgNums(3) @@ -57,7 +63,9 @@ func ProcessSetting(process *gou.Process) interface{} { } // ProcessSave xiang.workflow.Save 保存工作流节点信息 -// args: [工作流名称*, 当前用户ID*, 节点名称*, 关联数据ID*, 输入数据*, 输出数据] (输入数据: {"data":{}, "form":{}} data 关联数据记录信息, form 工作流body表单信息, 输出数据: {"foo":"bar"} ) +// +// args: [工作流名称*, 当前用户ID*, 节点名称*, 关联数据ID*, 输入数据*, 输出数据] (输入数据: {"data":{}, "form":{}} data 关联数据记录信息, form 工作流body表单信息, 输出数据: {"foo":"bar"} ) +// // return: map[string]interface{} 工作流数据记录 func ProcessSave(process *gou.Process) interface{} { process.ValidateArgNums(5) @@ -71,7 +79,9 @@ func ProcessSave(process *gou.Process) interface{} { } // ProcessNext xiang.workflow.Next 进入下一个节点 -// args: [工作流名称*, 当前用户ID*, 工作流ID*, 输出数据*] (输出数据: {"foo":"bar"} ) +// +// args: [工作流名称*, 当前用户ID*, 工作流ID*, 输出数据*] (输出数据: {"foo":"bar"} ) +// // return: map[string]interface{} 工作流数据记录 func ProcessNext(process *gou.Process) interface{} { process.ValidateArgNums(4) @@ -81,7 +91,9 @@ func ProcessNext(process *gou.Process) interface{} { } // ProcessGoto xiang.workflow.Goto 跳转到指定节点 -// args: [工作流名称*, 当前用户ID*, 工作流ID*, 节点名称*, 输出数据*] (输出数据: {"foo":"bar"} ) +// +// args: [工作流名称*, 当前用户ID*, 工作流ID*, 节点名称*, 输出数据*] (输出数据: {"foo":"bar"} ) +// // return: map[string]interface{} 工作流数据记录 func ProcessGoto(process *gou.Process) interface{} { process.ValidateArgNums(5) @@ -91,7 +103,9 @@ func ProcessGoto(process *gou.Process) interface{} { } // ProcessStatus xiang.workflow.Status 更新工作流状态 -// args: [工作流名称*, 当前用户ID*, 工作流ID*, 状态名称*, 输出数据*] (输出数据: {"foo":"bar"} ) +// +// args: [工作流名称*, 当前用户ID*, 工作流ID*, 状态名称*, 输出数据*] (输出数据: {"foo":"bar"} ) +// // return: map[string]interface{} 工作流数据记录 func ProcessStatus(process *gou.Process) interface{} { process.ValidateArgNums(5) @@ -101,7 +115,9 @@ func ProcessStatus(process *gou.Process) interface{} { } // ProcessDone xiang.workflow.Done 标记结束流程 -// args: [工作流名称*, 当前用户ID*, 工作流ID*, 输出数据*] (输出数据: {"foo":"bar"} ) +// +// args: [工作流名称*, 当前用户ID*, 工作流ID*, 输出数据*] (输出数据: {"foo":"bar"} ) +// // return: map[string]interface{} 工作流数据记录 func ProcessDone(process *gou.Process) interface{} { process.ValidateArgNums(4) @@ -111,7 +127,9 @@ func ProcessDone(process *gou.Process) interface{} { } // ProcessClose xiang.workflow.Close 标记关闭流程 -// args: [工作流名称*, 当前用户ID*, 工作流ID*, 输出数据*] (输出数据: {"foo":"bar"} ) +// +// args: [工作流名称*, 当前用户ID*, 工作流ID*, 输出数据*] (输出数据: {"foo":"bar"} ) +// // return: map[string]interface{} 工作流数据记录 func ProcessClose(process *gou.Process) interface{} { process.ValidateArgNums(4) @@ -121,7 +139,9 @@ func ProcessClose(process *gou.Process) interface{} { } // ProcessReset xiang.workflow.Reset 标记重置流程 -// args: [工作流名称*, 当前用户ID*, 工作流ID*, 输出数据*] (输出数据: {"foo":"bar"} ) +// +// args: [工作流名称*, 当前用户ID*, 工作流ID*, 输出数据*] (输出数据: {"foo":"bar"} ) +// // return: map[string]interface{} 工作流数据记录 func ProcessReset(process *gou.Process) interface{} { process.ValidateArgNums(4) From 9db84db7cc89f2455cc49da0557b6d45deb4c09c Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 12 Oct 2022 20:59:07 +0800 Subject: [PATCH 3/3] [fix] unit tests data --- widgets/app/app_test.go | 2 +- widgets/login/login_test.go | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/widgets/app/app_test.go b/widgets/app/app_test.go index 5663bf07..4409f8ef 100644 --- a/widgets/app/app_test.go +++ b/widgets/app/app_test.go @@ -133,7 +133,7 @@ func TestProcessXgen(t *testing.T) { assert.Equal(t, "/x/Table/pet", xgen.Get("login.entry.user")) assert.Equal(t, "/api/__yao/login/user/captcha?type=digit", xgen.Get("login.user.captcha")) assert.Equal(t, "/api/__yao/login/user", xgen.Get("login.user.login")) - assert.Equal(t, "/images/login/cover.svg", xgen.Get("login.layout.cover")) + assert.Equal(t, "/assets/images/login/cover.svg", xgen.Get("login.layout.cover")) assert.Equal(t, "/api/__yao/app/icons/app.ico", xgen.Get("favicon")) assert.Equal(t, "/api/__yao/app/icons/app.png", xgen.Get("logo")) assert.Equal(t, os.Getenv("YAO_ENV"), xgen.Get("mode")) diff --git a/widgets/login/login_test.go b/widgets/login/login_test.go index 76c97b7a..c1306346 100644 --- a/widgets/login/login_test.go +++ b/widgets/login/login_test.go @@ -27,7 +27,7 @@ func TestLoad(t *testing.T) { assert.Equal(t, "yao.login.Admin", Logins["admin"].Action.Process) assert.Equal(t, []string{":payload"}, Logins["admin"].Action.Args) assert.Equal(t, "yao.utils.Captcha", Logins["admin"].Layout.Captcha) - assert.Equal(t, "/images/login/cover.svg", Logins["admin"].Layout.Cover) + assert.Equal(t, "/assets/images/login/cover.svg", Logins["admin"].Layout.Cover) assert.Equal(t, "/x/Chart/dashboard", Logins["admin"].Layout.Entry) assert.Equal(t, "https://yaoapps.com", Logins["admin"].Layout.Site) assert.Equal(t, "Make Your Dream With Yao App Engine", Logins["admin"].Layout.Slogan) @@ -37,7 +37,7 @@ func TestLoad(t *testing.T) { assert.Equal(t, "scripts.user.Login", Logins["user"].Action.Process) assert.Equal(t, []string{":payload"}, Logins["user"].Action.Args) assert.Equal(t, "yao.utils.Captcha", Logins["user"].Layout.Captcha) - assert.Equal(t, "/images/login/cover.svg", Logins["user"].Layout.Cover) + assert.Equal(t, "/assets/images/login/cover.svg", Logins["user"].Layout.Cover) assert.Equal(t, "/x/Table/pet", Logins["user"].Layout.Entry) assert.Equal(t, "https://yaoapps.com/doc", Logins["user"].Layout.Site) assert.Equal(t, "Make Your Dream With Yao App Engine", Logins["user"].Layout.Slogan) @@ -59,20 +59,20 @@ func TestLoadHK(t *testing.T) { assert.Equal(t, "yao.login.Admin", Logins["admin"].Action.Process) assert.Equal(t, []string{":payload"}, Logins["admin"].Action.Args) assert.Equal(t, "yao.utils.Captcha", Logins["admin"].Layout.Captcha) - assert.Equal(t, "/images/login/cover.svg", Logins["admin"].Layout.Cover) + assert.Equal(t, "/assets/images/login/cover.svg", Logins["admin"].Layout.Cover) assert.Equal(t, "/x/Chart/dashboard", Logins["admin"].Layout.Entry) assert.Equal(t, "https://yaoapps.com", Logins["admin"].Layout.Site) - assert.Equal(t, "夢想讓我們與眾不同", Logins["admin"].Layout.Slogan) + assert.Equal(t, "和 Yao App Engine 一起,為夢想而努力", Logins["admin"].Layout.Slogan) assert.Equal(t, "user", Logins["user"].ID) assert.Equal(t, "用戶登錄", Logins["user"].Name) assert.Equal(t, "scripts.user.Login", Logins["user"].Action.Process) assert.Equal(t, []string{":payload"}, Logins["user"].Action.Args) assert.Equal(t, "yao.utils.Captcha", Logins["user"].Layout.Captcha) - assert.Equal(t, "/images/login/cover.svg", Logins["user"].Layout.Cover) + assert.Equal(t, "/assets/images/login/cover.svg", Logins["user"].Layout.Cover) assert.Equal(t, "/x/Table/pet", Logins["user"].Layout.Entry) assert.Equal(t, "https://yaoapps.com/doc", Logins["user"].Layout.Site) - assert.Equal(t, "夢想讓我們與眾不同", Logins["user"].Layout.Slogan) + assert.Equal(t, "和 Yao App Engine 一起,為夢想而努力", Logins["user"].Layout.Slogan) } func TestLoadCN(t *testing.T) { @@ -91,20 +91,20 @@ func TestLoadCN(t *testing.T) { assert.Equal(t, "yao.login.Admin", Logins["admin"].Action.Process) assert.Equal(t, []string{":payload"}, Logins["admin"].Action.Args) assert.Equal(t, "yao.utils.Captcha", Logins["admin"].Layout.Captcha) - assert.Equal(t, "/images/login/cover.svg", Logins["admin"].Layout.Cover) + assert.Equal(t, "/assets/images/login/cover.svg", Logins["admin"].Layout.Cover) assert.Equal(t, "/x/Chart/dashboard", Logins["admin"].Layout.Entry) assert.Equal(t, "https://yaoapps.com", Logins["admin"].Layout.Site) - assert.Equal(t, "梦想让我们与众不同", Logins["admin"].Layout.Slogan) + assert.Equal(t, "和 Yao App Engine 一起,为梦想而努力", Logins["admin"].Layout.Slogan) assert.Equal(t, "user", Logins["user"].ID) assert.Equal(t, "用户登录", Logins["user"].Name) assert.Equal(t, "scripts.user.Login", Logins["user"].Action.Process) assert.Equal(t, []string{":payload"}, Logins["user"].Action.Args) assert.Equal(t, "yao.utils.Captcha", Logins["user"].Layout.Captcha) - assert.Equal(t, "/images/login/cover.svg", Logins["user"].Layout.Cover) + assert.Equal(t, "/assets/images/login/cover.svg", Logins["user"].Layout.Cover) assert.Equal(t, "/x/Table/pet", Logins["user"].Layout.Entry) assert.Equal(t, "https://yaoapps.com/doc", Logins["user"].Layout.Site) - assert.Equal(t, "梦想让我们与众不同", Logins["user"].Layout.Slogan) + assert.Equal(t, "和 Yao App Engine 一起,为梦想而努力", Logins["user"].Layout.Slogan) } func TestExport(t *testing.T) {