[add] migrate plugin
This commit is contained in:
parent
1240d83078
commit
292fad2911
6 changed files with 80 additions and 27 deletions
8
.github/workflows/pr-test.yml
vendored
8
.github/workflows/pr-test.yml
vendored
|
|
@ -46,6 +46,7 @@ env:
|
|||
DEMO_APP: ${{ github.WORKSPACE }}/../app
|
||||
|
||||
YAO_TEST_APPLICATION: ${{ github.WORKSPACE }}/../app
|
||||
YAO_EXTENSION_ROOT: ${{ github.WORKSPACE }}/../extension
|
||||
|
||||
jobs:
|
||||
UnitTest:
|
||||
|
|
@ -145,6 +146,12 @@ jobs:
|
|||
repository: yaoapp/yao-dev-app
|
||||
path: app
|
||||
|
||||
- name: Checkout Extension
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
repository: yaoapp/yao-extensions-dev
|
||||
path: extension
|
||||
|
||||
- name: Move Kun, Xun, Gou, V8Go
|
||||
run: |
|
||||
mv kun ../
|
||||
|
|
@ -152,6 +159,7 @@ jobs:
|
|||
mv gou ../
|
||||
mv v8go ../
|
||||
mv app ../
|
||||
mv extension ../
|
||||
ls -l .
|
||||
ls -l ../
|
||||
|
||||
|
|
|
|||
10
.github/workflows/unit-test.yml
vendored
10
.github/workflows/unit-test.yml
vendored
|
|
@ -50,6 +50,7 @@ env:
|
|||
DEMO_APP: ${{ github.WORKSPACE }}/../app
|
||||
|
||||
YAO_TEST_APPLICATION: ${{ github.WORKSPACE }}/../app
|
||||
YAO_EXTENSION_ROOT: ${{ github.WORKSPACE }}/../extension
|
||||
|
||||
jobs:
|
||||
unit-test:
|
||||
|
|
@ -102,13 +103,20 @@ jobs:
|
|||
repository: yaoapp/yao-dev-app
|
||||
path: app
|
||||
|
||||
- name: Move Kun, Xun, Gou, V8Go
|
||||
- name: Checkout Extension
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
repository: yaoapp/yao-extensions-dev
|
||||
path: extension
|
||||
|
||||
- name: Move Kun, Xun, Gou, V8Go, Extension
|
||||
run: |
|
||||
mv kun ../
|
||||
mv xun ../
|
||||
mv gou ../
|
||||
mv v8go ../
|
||||
mv app ../
|
||||
mv extension ../
|
||||
ls -l .
|
||||
ls -l ../
|
||||
|
||||
|
|
|
|||
2
Makefile
2
Makefile
|
|
@ -9,7 +9,7 @@ COMMIT := $(shell git log | head -n 1 | awk '{print substr($$2, 0, 12)}')
|
|||
NOW := $(shell date +"%FT%T%z")
|
||||
|
||||
# ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
||||
TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api|model|flow|script|fs|i18n|connector|query' | grep -vE 'examples|tests*|config|widgets')
|
||||
TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api|model|flow|script|fs|i18n|connector|query|plugin' | grep -vE 'examples|tests*|config|widgets')
|
||||
TESTTAGS ?= ""
|
||||
|
||||
# TESTWIDGETS := $(shell $(GO) list ./widgets/...)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ type Config struct {
|
|||
Lang string `json:"lang,omitempty" env:"YAO_LANG" envDefault:"en-us"` // Default language setting
|
||||
TimeZone string `json:"timezone,omitempty" env:"YAO_TIMEZONE"` // Default TimeZone
|
||||
DataRoot string `json:"data_root,omitempty" env:"YAO_DATA_ROOT" envDefault:""` // DATA PATH
|
||||
ExtensionRoot string `json:"extension_root,omitempty" env:"YAO_EXTENSION_ROOT" envDefault:""` // Plugin, Wasm root PATH, Default is <YAO_ROOT> (<YAO_ROOT>/plugins <YAO_ROOT>/wasms)
|
||||
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 证书文件地址
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"github.com/yaoapp/gou/application"
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/yaoapp/gou/plugin"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/share"
|
||||
|
|
@ -9,9 +12,38 @@ import (
|
|||
|
||||
// Load 加载业务插件
|
||||
func Load(cfg config.Config) error {
|
||||
exts := []string{"*.so"}
|
||||
return application.App.Walk("apis", func(root, file string, isdir bool) error {
|
||||
_, err := plugin.Load(file, share.ID(root, file))
|
||||
|
||||
root, err := Root(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}, exts...)
|
||||
}
|
||||
|
||||
return filepath.Walk(root, func(file string, info fs.FileInfo, err error) error {
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !strings.HasSuffix(file, ".so") && !strings.HasSuffix(file, ".dll") {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = plugin.Load(file, share.ID(root, file))
|
||||
return err
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// Root return plugin root
|
||||
func Root(cfg config.Config) (string, error) {
|
||||
root := filepath.Join(cfg.ExtensionRoot, "plugins")
|
||||
if cfg.ExtensionRoot == "" {
|
||||
root = filepath.Join(cfg.Root, "plugins")
|
||||
}
|
||||
|
||||
root, err := filepath.Abs(root)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return root, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,17 +7,21 @@ import (
|
|||
|
||||
"github.com/yaoapp/gou/plugin"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/test"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
test.Prepare(t, config.Conf)
|
||||
defer test.Clean()
|
||||
|
||||
Load(config.Conf)
|
||||
check(t)
|
||||
}
|
||||
|
||||
func check(t *testing.T) {
|
||||
keys := []string{}
|
||||
for key := range plugin.Plugins {
|
||||
keys = append(keys, key)
|
||||
ids := map[string]bool{}
|
||||
for id := range plugin.Plugins {
|
||||
ids[id] = true
|
||||
}
|
||||
assert.Equal(t, 1, len(keys))
|
||||
assert.True(t, ids["user"])
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue