From 507d39e01171fb5a565ef77c8a18e7e5a781907f Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 10 Nov 2022 00:10:38 +0800 Subject: [PATCH] [add] http.* processes & http JSAPI --- .github/workflows/release-linux.yml | 4 ++-- .github/workflows/release-macos.yml | 4 ++-- Makefile | 6 +++--- chart/process_test.go | 2 ++ engine/load.go | 7 +++++++ flow/flow_test.go | 2 ++ helper/hex_test.go | 3 +++ importer/init_test.go | 2 ++ network/process.go | 4 ++++ network/request.go | 4 ++++ network/request.process.go | 4 ++++ page/process_test.go | 2 ++ runtime/runtime.go | 18 ++++++++++++++++++ script/script_test.go | 3 +++ studio/studio_test.go | 2 ++ table/process_test.go | 2 ++ websocket/websocket_test.go | 3 +++ widget/widget_test.go | 2 ++ widgets/app/app_test.go | 2 ++ widgets/chart/chart_test.go | 3 ++- widgets/form/form_test.go | 3 ++- widgets/login/login_test.go | 5 +++-- widgets/table/table_test.go | 3 ++- widgets/test/engine.go | 3 ++- widgets/widgets_test.go | 3 ++- 25 files changed, 82 insertions(+), 14 deletions(-) create mode 100644 runtime/runtime.go diff --git a/.github/workflows/release-linux.yml b/.github/workflows/release-linux.yml index eaa8a1d3..388c5cc6 100644 --- a/.github/workflows/release-linux.yml +++ b/.github/workflows/release-linux.yml @@ -69,13 +69,13 @@ jobs: - name: Checkout XGen v0.9 uses: actions/checkout@v2 with: - repository: yaoapp/xgen + repository: yaoapp/xgen-deprecated path: xgen-v0.9 - name: Checkout XGen v1.0 uses: actions/checkout@v2 with: - repository: yaoapp/xgen-next + repository: yaoapp/xgen # ref: 9ce17a22904b3f09de90f08abbbdaf42f6b0ef68 path: xgen-v1.0 diff --git a/.github/workflows/release-macos.yml b/.github/workflows/release-macos.yml index 32d1e3d7..eb32f70d 100644 --- a/.github/workflows/release-macos.yml +++ b/.github/workflows/release-macos.yml @@ -61,13 +61,13 @@ jobs: - name: Checkout XGen v0.9 uses: actions/checkout@v2 with: - repository: yaoapp/xgen + repository: yaoapp/xgen-deprecated path: xgen-v0.9 - name: Checkout XGen v1.0 uses: actions/checkout@v2 with: - repository: yaoapp/xgen-next + repository: yaoapp/xgen # ref: 9ce17a22904b3f09de90f08abbbdaf42f6b0ef68 path: xgen-v1.0 diff --git a/Makefile b/Makefile index 5e5b7510..318a9e15 100644 --- a/Makefile +++ b/Makefile @@ -273,7 +273,7 @@ release: clean # Building XGEN v1.0 export NODE_ENV=production - git clone https://github.com/YaoApp/xgen-next.git .tmp/xgen/v1.0 + git clone https://github.com/YaoApp/xgen.git .tmp/xgen/v1.0 # cd .tmp/xgen/v1.0 && git checkout 9ce17a22904b3f09de90f08abbbdaf42f6b0ef68 echo "BASE=__yao_admin_root" > .tmp/xgen/v1.0/packages/xgen/.env cd .tmp/xgen/v1.0 && pnpm install && pnpm run build @@ -310,7 +310,7 @@ linux-release: clean mkdir .tmp # Building XGEN v0.9 - git clone https://github.com/YaoApp/xgen.git .tmp/xgen/v0.9 + git clone https://github.com/YaoApp/xgen-deprecated.git .tmp/xgen/v0.9 sed -ie "s/url('\/icon/url('\/xiang\/icon/g" .tmp/xgen/v0.9/public/icon/md_icon.css cd .tmp/xgen/v0.9 && yarn install && yarn build mkdir -p .tmp/xgen/v0.9 @@ -318,7 +318,7 @@ linux-release: clean # Building XGEN v1.0 export NODE_ENV=production - git clone https://github.com/YaoApp/xgen-next.git .tmp/xgen/v1.0 + git clone https://github.com/YaoApp/xgen.git .tmp/xgen/v1.0 rm -f .tmp/xgen/v1.0/pnpm-lock.yaml echo "BASE=__yao_admin_root" > .tmp/xgen/v1.0/packages/xgen/.env cd .tmp/xgen/v1.0 && pnpm install && pnpm run build diff --git a/chart/process_test.go b/chart/process_test.go index 9a7ed568..c0d883ff 100644 --- a/chart/process_test.go +++ b/chart/process_test.go @@ -14,10 +14,12 @@ import ( _ "github.com/yaoapp/yao/helper" "github.com/yaoapp/yao/model" "github.com/yaoapp/yao/query" + "github.com/yaoapp/yao/runtime" "github.com/yaoapp/yao/share" ) func init() { + runtime.Load(config.Conf) share.DBConnect(config.Conf.DB) model.Load(config.Conf) query.Load(config.Conf) diff --git a/engine/load.go b/engine/load.go index 26348a8a..2060d03e 100644 --- a/engine/load.go +++ b/engine/load.go @@ -23,6 +23,7 @@ import ( "github.com/yaoapp/yao/page" "github.com/yaoapp/yao/plugin" "github.com/yaoapp/yao/query" + "github.com/yaoapp/yao/runtime" "github.com/yaoapp/yao/schedule" "github.com/yaoapp/yao/script" "github.com/yaoapp/yao/share" @@ -40,6 +41,12 @@ import ( func Load(cfg config.Config) (err error) { defer func() { err = exception.Catch(recover()) }() + // Load Runtime + err = runtime.Load(cfg) + if err != nil { + printErr(cfg.Mode, "Runtime", err) + } + // 加载应用信息 // 第一步: 加载应用信息 app.Load(cfg) diff --git a/flow/flow_test.go b/flow/flow_test.go index b1b06c19..96619c5a 100644 --- a/flow/flow_test.go +++ b/flow/flow_test.go @@ -6,9 +6,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/yaoapp/gou" "github.com/yaoapp/yao/config" + "github.com/yaoapp/yao/runtime" ) func TestLoad(t *testing.T) { + runtime.Load(config.Conf) gou.Flows = make(map[string]*gou.Flow) Load(config.Conf) LoadFrom("not a path", "404.") diff --git a/helper/hex_test.go b/helper/hex_test.go index bca5e63a..dd1fee71 100644 --- a/helper/hex_test.go +++ b/helper/hex_test.go @@ -7,7 +7,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/yaoapp/gou" + "github.com/yaoapp/yao/config" "github.com/yaoapp/yao/flow" + "github.com/yaoapp/yao/runtime" "github.com/yaoapp/yao/share" ) @@ -35,6 +37,7 @@ func TestProcessHexToStringInFlow(t *testing.T) { } func TestProcessHexToStringInScript(t *testing.T) { + runtime.Load(config.Conf) testscirpt := path.Join(os.Getenv("YAO_DEV"), "tests", "scripts") share.LoadFrom(testscirpt) diff --git a/importer/init_test.go b/importer/init_test.go index f2976cf3..89b29419 100644 --- a/importer/init_test.go +++ b/importer/init_test.go @@ -7,11 +7,13 @@ import ( "github.com/yaoapp/yao/config" "github.com/yaoapp/yao/model" "github.com/yaoapp/yao/query" + "github.com/yaoapp/yao/runtime" "github.com/yaoapp/yao/script" "github.com/yaoapp/yao/share" ) func TestMain(m *testing.M) { + runtime.Load(config.Conf) share.DBConnect(config.Conf.DB) model.Load(config.Conf) query.Load(config.Conf) diff --git a/network/process.go b/network/process.go index 6c244dec..376a5b8e 100644 --- a/network/process.go +++ b/network/process.go @@ -1,5 +1,9 @@ package network +// ******************************************************* +// * DEPRECATED → http * +// ******************************************************* + import "github.com/yaoapp/gou" func init() { diff --git a/network/request.go b/network/request.go index 41db5a52..de0f1c80 100644 --- a/network/request.go +++ b/network/request.go @@ -1,5 +1,9 @@ package network +// ******************************************************* +// * DEPRECATED → http * +// ******************************************************* + import ( "bytes" "crypto/tls" diff --git a/network/request.process.go b/network/request.process.go index 40c71e68..0b28591f 100644 --- a/network/request.process.go +++ b/network/request.process.go @@ -6,6 +6,10 @@ import ( "github.com/yaoapp/gou" ) +// ******************************************************* +// * DEPRECATED → http * +// ******************************************************* + // ProcessPost xiang.helper.Post HTTP Post func ProcessPost(process *gou.Process) interface{} { process.ValidateArgNums(1) diff --git a/page/process_test.go b/page/process_test.go index ef56b914..0fb76648 100644 --- a/page/process_test.go +++ b/page/process_test.go @@ -12,10 +12,12 @@ import ( _ "github.com/yaoapp/yao/helper" "github.com/yaoapp/yao/model" "github.com/yaoapp/yao/query" + "github.com/yaoapp/yao/runtime" "github.com/yaoapp/yao/share" ) func init() { + runtime.Load(config.Conf) share.DBConnect(config.Conf.DB) model.Load(config.Conf) query.Load(config.Conf) diff --git a/runtime/runtime.go b/runtime/runtime.go new file mode 100644 index 00000000..1038f8d1 --- /dev/null +++ b/runtime/runtime.go @@ -0,0 +1,18 @@ +package runtime + +import ( + "github.com/yaoapp/gou" + "github.com/yaoapp/gou/runtime" + "github.com/yaoapp/yao/config" + "github.com/yaoapp/yao/fs" +) + +// Load runtime +func Load(cfg config.Config) error { + dataRoot, err := fs.Root(cfg) + if err != nil { + return err + } + gou.LoadRuntime(runtime.Option{FileRoot: dataRoot}) + return nil +} diff --git a/script/script_test.go b/script/script_test.go index 8f78c4ca..c16dfb35 100644 --- a/script/script_test.go +++ b/script/script_test.go @@ -7,9 +7,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/yaoapp/gou" + "github.com/yaoapp/yao/config" + "github.com/yaoapp/yao/runtime" ) func init() { + runtime.Load(config.Conf) rootLib := path.Join(os.Getenv("YAO_DEV"), "/tests/scripts") LoadFrom(rootLib, "") } diff --git a/studio/studio_test.go b/studio/studio_test.go index a3db0ff4..e3d08cd9 100644 --- a/studio/studio_test.go +++ b/studio/studio_test.go @@ -13,12 +13,14 @@ import ( "github.com/yaoapp/gou" "github.com/yaoapp/yao/config" "github.com/yaoapp/yao/helper" + "github.com/yaoapp/yao/runtime" ) type kv map[string]interface{} type arr []interface{} func TestLoad(t *testing.T) { + runtime.Load(config.Conf) err := Load(config.Conf) if err != nil { t.Fatal(err) diff --git a/table/process_test.go b/table/process_test.go index 0dd575e3..8be6d549 100644 --- a/table/process_test.go +++ b/table/process_test.go @@ -16,11 +16,13 @@ import ( _ "github.com/yaoapp/yao/helper" "github.com/yaoapp/yao/model" "github.com/yaoapp/yao/query" + "github.com/yaoapp/yao/runtime" "github.com/yaoapp/yao/script" "github.com/yaoapp/yao/share" ) func init() { + runtime.Load(config.Conf) share.DBConnect(config.Conf.DB) model.Load(config.Conf) share.Load(config.Conf) diff --git a/websocket/websocket_test.go b/websocket/websocket_test.go index 24d0df54..a2b4fd4c 100644 --- a/websocket/websocket_test.go +++ b/websocket/websocket_test.go @@ -12,16 +12,19 @@ import ( "github.com/yaoapp/gou" "github.com/yaoapp/gou/websocket" "github.com/yaoapp/yao/config" + "github.com/yaoapp/yao/runtime" "github.com/yaoapp/yao/script" ) func TestLoad(t *testing.T) { + runtime.Load(config.Conf) Load(config.Conf) LoadFrom("not a path", "404.") check(t) } func TestWebSocketOpen(t *testing.T) { + runtime.Load(config.Conf) Load(config.Conf) script.Load(config.Conf) srv, url := serve(t) diff --git a/widget/widget_test.go b/widget/widget_test.go index 7183d019..1c45425a 100644 --- a/widget/widget_test.go +++ b/widget/widget_test.go @@ -7,10 +7,12 @@ import ( "github.com/yaoapp/gou" "github.com/yaoapp/kun/any" "github.com/yaoapp/yao/config" + "github.com/yaoapp/yao/runtime" "github.com/yaoapp/yao/share" ) func TestLoad(t *testing.T) { + runtime.Load(config.Conf) share.DBConnect(config.Conf.DB) // 创建数据库连接 Load(config.Conf) LoadFrom("not a path") diff --git a/widgets/app/app_test.go b/widgets/app/app_test.go index 10cb6eea..bc27280d 100644 --- a/widgets/app/app_test.go +++ b/widgets/app/app_test.go @@ -11,6 +11,7 @@ import ( "github.com/yaoapp/yao/config" "github.com/yaoapp/yao/flow" "github.com/yaoapp/yao/i18n" + "github.com/yaoapp/yao/runtime" "github.com/yaoapp/yao/script" "github.com/yaoapp/yao/widgets/login" ) @@ -274,6 +275,7 @@ func TestProcessService(t *testing.T) { } func loadApp(t *testing.T) { + runtime.Load(config.Conf) err := script.Load(config.Conf) if err != nil { diff --git a/widgets/chart/chart_test.go b/widgets/chart/chart_test.go index 0dacf10a..ba0d6035 100644 --- a/widgets/chart/chart_test.go +++ b/widgets/chart/chart_test.go @@ -7,6 +7,7 @@ import ( "github.com/yaoapp/yao/config" "github.com/yaoapp/yao/i18n" "github.com/yaoapp/yao/model" + "github.com/yaoapp/yao/runtime" "github.com/yaoapp/yao/script" "github.com/yaoapp/yao/share" ) @@ -21,7 +22,7 @@ func TestLoad(t *testing.T) { } func prepare(t *testing.T, language ...string) { - + runtime.Load(config.Conf) i18n.Load(config.Conf) share.DBConnect(config.Conf.DB) // removed later diff --git a/widgets/form/form_test.go b/widgets/form/form_test.go index 28482365..c60c5a5f 100644 --- a/widgets/form/form_test.go +++ b/widgets/form/form_test.go @@ -7,6 +7,7 @@ import ( "github.com/yaoapp/yao/config" "github.com/yaoapp/yao/i18n" "github.com/yaoapp/yao/model" + "github.com/yaoapp/yao/runtime" "github.com/yaoapp/yao/script" "github.com/yaoapp/yao/share" "github.com/yaoapp/yao/table" @@ -24,7 +25,7 @@ func TestLoad(t *testing.T) { } func prepare(t *testing.T, language ...string) { - + runtime.Load(config.Conf) i18n.Load(config.Conf) share.DBConnect(config.Conf.DB) // removed later diff --git a/widgets/login/login_test.go b/widgets/login/login_test.go index 1655de67..28596c27 100644 --- a/widgets/login/login_test.go +++ b/widgets/login/login_test.go @@ -9,10 +9,11 @@ import ( "github.com/yaoapp/gou" "github.com/yaoapp/yao/config" "github.com/yaoapp/yao/i18n" + "github.com/yaoapp/yao/runtime" ) func TestLoad(t *testing.T) { - + runtime.Load(config.Conf) i18n.Load(config.Conf) err := Load(config.Conf) if err != nil { @@ -43,7 +44,7 @@ func TestLoad(t *testing.T) { } func TestLoadHK(t *testing.T) { - + runtime.Load(config.Conf) i18n.Load(config.Conf) err := Load(config.Conf) if err != nil { diff --git a/widgets/table/table_test.go b/widgets/table/table_test.go index 8aead9cf..0f38e181 100644 --- a/widgets/table/table_test.go +++ b/widgets/table/table_test.go @@ -8,6 +8,7 @@ import ( "github.com/yaoapp/yao/config" "github.com/yaoapp/yao/flow" "github.com/yaoapp/yao/model" + "github.com/yaoapp/yao/runtime" "github.com/yaoapp/yao/script" "github.com/yaoapp/yao/widgets/app" "github.com/yaoapp/yao/widgets/component" @@ -34,7 +35,7 @@ func TestLoadID(t *testing.T) { } func prepare(t *testing.T, language ...string) { - + runtime.Load(config.Conf) err := test.LoadEngine(language...) if err != nil { t.Fatal(err) diff --git a/widgets/test/engine.go b/widgets/test/engine.go index ba9efcf4..15f051c8 100644 --- a/widgets/test/engine.go +++ b/widgets/test/engine.go @@ -8,12 +8,13 @@ import ( "github.com/yaoapp/yao/config" "github.com/yaoapp/yao/i18n" "github.com/yaoapp/yao/model" + "github.com/yaoapp/yao/runtime" "github.com/yaoapp/yao/share" ) // LoadEngine load engine func LoadEngine(language ...string) error { - + runtime.Load(config.Conf) i18n.Load(config.Conf) share.DBConnect(config.Conf.DB) // removed later gou.LoadCrypt(`{}`, "PASSWORD") diff --git a/widgets/widgets_test.go b/widgets/widgets_test.go index 379251a7..2046f19d 100644 --- a/widgets/widgets_test.go +++ b/widgets/widgets_test.go @@ -7,6 +7,7 @@ import ( "github.com/yaoapp/yao/config" "github.com/yaoapp/yao/i18n" "github.com/yaoapp/yao/model" + "github.com/yaoapp/yao/runtime" "github.com/yaoapp/yao/script" "github.com/yaoapp/yao/share" ) @@ -18,7 +19,7 @@ func TestLoad(t *testing.T) { } func prepare(t *testing.T, language ...string) { - + runtime.Load(config.Conf) i18n.Load(config.Conf) share.DBConnect(config.Conf.DB) // removed later