[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
|
DEMO_APP: ${{ github.WORKSPACE }}/../app
|
||||||
|
|
||||||
YAO_TEST_APPLICATION: ${{ github.WORKSPACE }}/../app
|
YAO_TEST_APPLICATION: ${{ github.WORKSPACE }}/../app
|
||||||
|
YAO_EXTENSION_ROOT: ${{ github.WORKSPACE }}/../extension
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
UnitTest:
|
UnitTest:
|
||||||
|
|
@ -145,6 +146,12 @@ jobs:
|
||||||
repository: yaoapp/yao-dev-app
|
repository: yaoapp/yao-dev-app
|
||||||
path: app
|
path: app
|
||||||
|
|
||||||
|
- name: Checkout Extension
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
repository: yaoapp/yao-extensions-dev
|
||||||
|
path: extension
|
||||||
|
|
||||||
- name: Move Kun, Xun, Gou, V8Go
|
- name: Move Kun, Xun, Gou, V8Go
|
||||||
run: |
|
run: |
|
||||||
mv kun ../
|
mv kun ../
|
||||||
|
|
@ -152,6 +159,7 @@ jobs:
|
||||||
mv gou ../
|
mv gou ../
|
||||||
mv v8go ../
|
mv v8go ../
|
||||||
mv app ../
|
mv app ../
|
||||||
|
mv extension ../
|
||||||
ls -l .
|
ls -l .
|
||||||
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
|
DEMO_APP: ${{ github.WORKSPACE }}/../app
|
||||||
|
|
||||||
YAO_TEST_APPLICATION: ${{ github.WORKSPACE }}/../app
|
YAO_TEST_APPLICATION: ${{ github.WORKSPACE }}/../app
|
||||||
|
YAO_EXTENSION_ROOT: ${{ github.WORKSPACE }}/../extension
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
unit-test:
|
unit-test:
|
||||||
|
|
@ -102,13 +103,20 @@ jobs:
|
||||||
repository: yaoapp/yao-dev-app
|
repository: yaoapp/yao-dev-app
|
||||||
path: 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: |
|
run: |
|
||||||
mv kun ../
|
mv kun ../
|
||||||
mv xun ../
|
mv xun ../
|
||||||
mv gou ../
|
mv gou ../
|
||||||
mv v8go ../
|
mv v8go ../
|
||||||
mv app ../
|
mv app ../
|
||||||
|
mv extension ../
|
||||||
ls -l .
|
ls -l .
|
||||||
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")
|
NOW := $(shell date +"%FT%T%z")
|
||||||
|
|
||||||
# ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
# 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 ?= ""
|
TESTTAGS ?= ""
|
||||||
|
|
||||||
# TESTWIDGETS := $(shell $(GO) list ./widgets/...)
|
# TESTWIDGETS := $(shell $(GO) list ./widgets/...)
|
||||||
|
|
|
||||||
|
|
@ -2,22 +2,23 @@ package config
|
||||||
|
|
||||||
// Config 象传应用引擎配置
|
// Config 象传应用引擎配置
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Mode string `json:"mode,omitempty" env:"YAO_ENV" envDefault:"production"` // 象传引擎启动模式 production/development
|
Mode string `json:"mode,omitempty" env:"YAO_ENV" envDefault:"production"` // 象传引擎启动模式 production/development
|
||||||
Root string `json:"root,omitempty" env:"YAO_ROOT" envDefault:"."` // 应用根目录
|
Root string `json:"root,omitempty" env:"YAO_ROOT" envDefault:"."` // 应用根目录
|
||||||
Lang string `json:"lang,omitempty" env:"YAO_LANG" envDefault:"en-us"` // Default language setting
|
Lang string `json:"lang,omitempty" env:"YAO_LANG" envDefault:"en-us"` // Default language setting
|
||||||
TimeZone string `json:"timezone,omitempty" env:"YAO_TIMEZONE"` // Default TimeZone
|
TimeZone string `json:"timezone,omitempty" env:"YAO_TIMEZONE"` // Default TimeZone
|
||||||
DataRoot string `json:"data_root,omitempty" env:"YAO_DATA_ROOT" envDefault:""` // DATA PATH
|
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"` // 服务监听地址
|
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)
|
||||||
Port int `json:"port,omitempty" env:"YAO_PORT" envDefault:"5099"` // 服务监听端口
|
Host string `json:"host,omitempty" env:"YAO_HOST" envDefault:"0.0.0.0"` // 服务监听地址
|
||||||
Cert string `json:"cert,omitempty" env:"YAO_CERT"` // HTTPS 证书文件地址
|
Port int `json:"port,omitempty" env:"YAO_PORT" envDefault:"5099"` // 服务监听端口
|
||||||
Key string `json:"key,omitempty" env:"YAO_KEY"` // HTTPS 证书密钥地址
|
Cert string `json:"cert,omitempty" env:"YAO_CERT"` // HTTPS 证书文件地址
|
||||||
Log string `json:"log,omitempty" env:"YAO_LOG"` // 服务日志地址
|
Key string `json:"key,omitempty" env:"YAO_KEY"` // HTTPS 证书密钥地址
|
||||||
LogMode string `json:"log_mode,omitempty" env:"YAO_LOG_MODE" envDefault:"TEXT"` // 服务日志模式 JSON|TEXT
|
Log string `json:"log,omitempty" env:"YAO_LOG"` // 服务日志地址
|
||||||
JWTSecret string `json:"jwt_secret,omitempty" env:"YAO_JWT_SECRET"` // JWT 密钥
|
LogMode string `json:"log_mode,omitempty" env:"YAO_LOG_MODE" envDefault:"TEXT"` // 服务日志模式 JSON|TEXT
|
||||||
DB DBConfig `json:"db,omitempty"` // 数据库配置
|
JWTSecret string `json:"jwt_secret,omitempty" env:"YAO_JWT_SECRET"` // JWT 密钥
|
||||||
AllowFrom []string `json:"allowfrom,omitempty" envSeparator:"|" env:"YAO_ALLOW_FROM"` // Domain list the separator is |
|
DB DBConfig `json:"db,omitempty"` // 数据库配置
|
||||||
Session SessionConfig `json:"session,omitempty"` // Session Config
|
AllowFrom []string `json:"allowfrom,omitempty" envSeparator:"|" env:"YAO_ALLOW_FROM"` // Domain list the separator is |
|
||||||
Studio StudioConfig `json:"studio,omitempty"` // Studio config
|
Session SessionConfig `json:"session,omitempty"` // Session Config
|
||||||
|
Studio StudioConfig `json:"studio,omitempty"` // Studio config
|
||||||
}
|
}
|
||||||
|
|
||||||
// StudioConfig the studio config
|
// StudioConfig the studio config
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/yaoapp/gou/application"
|
"io/fs"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/yaoapp/gou/plugin"
|
"github.com/yaoapp/gou/plugin"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/share"
|
||||||
|
|
@ -9,9 +12,38 @@ import (
|
||||||
|
|
||||||
// Load 加载业务插件
|
// Load 加载业务插件
|
||||||
func Load(cfg config.Config) error {
|
func Load(cfg config.Config) error {
|
||||||
exts := []string{"*.so"}
|
|
||||||
return application.App.Walk("apis", func(root, file string, isdir bool) error {
|
root, err := Root(cfg)
|
||||||
_, err := plugin.Load(file, share.ID(root, file))
|
if err != nil {
|
||||||
return err
|
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/gou/plugin"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
|
"github.com/yaoapp/yao/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoad(t *testing.T) {
|
func TestLoad(t *testing.T) {
|
||||||
|
test.Prepare(t, config.Conf)
|
||||||
|
defer test.Clean()
|
||||||
|
|
||||||
Load(config.Conf)
|
Load(config.Conf)
|
||||||
check(t)
|
check(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func check(t *testing.T) {
|
func check(t *testing.T) {
|
||||||
keys := []string{}
|
ids := map[string]bool{}
|
||||||
for key := range plugin.Plugins {
|
for id := range plugin.Plugins {
|
||||||
keys = append(keys, key)
|
ids[id] = true
|
||||||
}
|
}
|
||||||
assert.Equal(t, 1, len(keys))
|
assert.True(t, ids["user"])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue