Skip to content

Commit

Permalink
[add] migrate plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Feb 2, 2023
1 parent 1240d83 commit 292fad2
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 27 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ env:
DEMO_APP: ${{ github.WORKSPACE }}/../app

YAO_TEST_APPLICATION: ${{ github.WORKSPACE }}/../app
YAO_EXTENSION_ROOT: ${{ github.WORKSPACE }}/../extension

jobs:
UnitTest:
Expand Down Expand Up @@ -145,13 +146,20 @@ 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 ../
mv xun ../
mv gou ../
mv v8go ../
mv app ../
mv extension ../
ls -l .
ls -l ../
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 ../
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/...)
Expand Down
33 changes: 17 additions & 16 deletions config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ 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:"."` // 应用根目录
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
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
JWTSecret string `json:"jwt_secret,omitempty" env:"YAO_JWT_SECRET"` // JWT 密钥
DB DBConfig `json:"db,omitempty"` // 数据库配置
AllowFrom []string `json:"allowfrom,omitempty" envSeparator:"|" env:"YAO_ALLOW_FROM"` // Domain list the separator is |
Session SessionConfig `json:"session,omitempty"` // Session Config
Studio StudioConfig `json:"studio,omitempty"` // Studio config
Mode string `json:"mode,omitempty" env:"YAO_ENV" envDefault:"production"` // 象传引擎启动模式 production/development
Root string `json:"root,omitempty" env:"YAO_ROOT" envDefault:"."` // 应用根目录
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 证书文件地址
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
JWTSecret string `json:"jwt_secret,omitempty" env:"YAO_JWT_SECRET"` // JWT 密钥
DB DBConfig `json:"db,omitempty"` // 数据库配置
AllowFrom []string `json:"allowfrom,omitempty" envSeparator:"|" env:"YAO_ALLOW_FROM"` // Domain list the separator is |
Session SessionConfig `json:"session,omitempty"` // Session Config
Studio StudioConfig `json:"studio,omitempty"` // Studio config
}

// StudioConfig the studio config
Expand Down
42 changes: 37 additions & 5 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,49 @@
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"
)

// 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
}

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
}, exts...)
})

}

// 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
}
12 changes: 8 additions & 4 deletions plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
}

0 comments on commit 292fad2

Please sign in to comment.