[change] refactor the app engine load func
This commit is contained in:
parent
8f7e1b3459
commit
8761a26d52
12 changed files with 398 additions and 191 deletions
2
.github/workflows/pr-test.yml
vendored
2
.github/workflows/pr-test.yml
vendored
|
|
@ -10,7 +10,7 @@ on:
|
|||
env:
|
||||
YAO_DEV: ${{ github.WORKSPACE }}
|
||||
YAO_ENV: development
|
||||
YAO_ROOT: ${{ github.WORKSPACE }}/tests
|
||||
YAO_ROOT: ${{ github.WORKSPACE }}/../app
|
||||
YAO_HOST: 0.0.0.0
|
||||
YAO_PORT: 5099
|
||||
YAO_SESSION: "memory"
|
||||
|
|
|
|||
2
.github/workflows/unit-test.yml
vendored
2
.github/workflows/unit-test.yml
vendored
|
|
@ -11,7 +11,7 @@ on:
|
|||
env:
|
||||
YAO_DEV: ${{ github.WORKSPACE }}
|
||||
YAO_ENV: development
|
||||
YAO_ROOT: ${{ github.WORKSPACE }}/tests
|
||||
YAO_ROOT: ${{ github.WORKSPACE }}/../app
|
||||
YAO_HOST: 0.0.0.0
|
||||
YAO_PORT: 5099
|
||||
YAO_SESSION: "memory"
|
||||
|
|
|
|||
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|plugin|cert|crypto|task|schedule|runtime|helper|utils|widget|importer|store|widgets' | grep -vE 'examples|tests*|config')
|
||||
TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api|model|flow|script|fs|i18n|connector|query|plugin|cert|crypto|task|schedule|runtime|helper|utils|widget|importer|store|widgets|engine' | grep -vE 'examples|tests*|config')
|
||||
TESTTAGS ?= ""
|
||||
|
||||
# TESTWIDGETS := $(shell $(GO) list ./widgets/...)
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
# 程序入口
|
||||
|
||||
加载各种文件
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
package engine
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/yaoapp/yao/config"
|
||||
)
|
||||
|
||||
var cfg config.Config
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
||||
// 加载模型等
|
||||
Load(config.Conf)
|
||||
|
||||
// Run test suites
|
||||
exitVal := m.Run()
|
||||
|
||||
// we can do clean up code here
|
||||
// gou.KillPlugins()
|
||||
|
||||
os.Exit(exitVal)
|
||||
}
|
||||
484
engine/load.go
484
engine/load.go
|
|
@ -3,10 +3,10 @@ package engine
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/yaoapp/gou/application"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/yao/api"
|
||||
"github.com/yaoapp/yao/cert"
|
||||
|
|
@ -19,34 +19,37 @@ import (
|
|||
"github.com/yaoapp/yao/model"
|
||||
"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"
|
||||
"github.com/yaoapp/yao/socket"
|
||||
"github.com/yaoapp/yao/store"
|
||||
"github.com/yaoapp/yao/studio"
|
||||
"github.com/yaoapp/yao/task"
|
||||
"github.com/yaoapp/yao/websocket"
|
||||
"github.com/yaoapp/yao/widget"
|
||||
"github.com/yaoapp/yao/widgets"
|
||||
)
|
||||
|
||||
// Load 根据配置加载 API, FLow, Model, Plugin
|
||||
// Load application engine
|
||||
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)
|
||||
// }
|
||||
// SET XGEN_BASE
|
||||
adminRoot := "yao"
|
||||
if share.App.Optional != nil {
|
||||
if root, has := share.App.Optional["adminRoot"]; has {
|
||||
adminRoot = fmt.Sprintf("%v", root)
|
||||
}
|
||||
}
|
||||
os.Setenv("XGEN_BASE", adminRoot)
|
||||
|
||||
// // 加载应用信息
|
||||
// // 第一步: 加载应用信息
|
||||
// app.Load(cfg)
|
||||
|
||||
// 加密密钥函数
|
||||
// model.LoadCrypt(fmt.Sprintf(`{"key":"%s"}`, cfg.DB.AESKey), "AES")
|
||||
// gou.LoadCrypt(`{}`, "PASSWORD")
|
||||
// load the application
|
||||
err = loadApp(cfg.Root)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Load Application", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Load Certs
|
||||
err = cert.Load(cfg)
|
||||
|
|
@ -54,7 +57,7 @@ func Load(cfg config.Config) (err error) {
|
|||
printErr(cfg.Mode, "Cert", err)
|
||||
}
|
||||
|
||||
// Load connectors
|
||||
// Load Connectors
|
||||
err = connector.Load(cfg)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Connector", err)
|
||||
|
|
@ -72,134 +75,100 @@ func Load(cfg config.Config) (err error) {
|
|||
printErr(cfg.Mode, "i18n", err)
|
||||
}
|
||||
|
||||
// Load Studio development mode only
|
||||
if cfg.Mode == "development" {
|
||||
err = studio.Load(cfg)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Studio", err)
|
||||
}
|
||||
// start v8 runtime
|
||||
err = runtime.Start(cfg)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Runtime", err)
|
||||
}
|
||||
|
||||
// 第二步: 建立数据库 & 会话连接
|
||||
err = share.DBConnect(cfg.DB) // 创建数据库连接
|
||||
// Make Database connections
|
||||
err = share.DBConnect(cfg.DB)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "DB", err)
|
||||
}
|
||||
|
||||
// share.SessionConnect(cfg.Session) // 创建会话服务器链接
|
||||
|
||||
// 加载应用引擎
|
||||
if os.Getenv("YAO_DEV") != "" {
|
||||
LoadEngine(filepath.Join(os.Getenv("YAO_DEV"), "/yao"))
|
||||
} else {
|
||||
LoadEngine()
|
||||
}
|
||||
|
||||
// 第三步: 加载数据分析引擎
|
||||
query.Load(cfg) // 加载数据分析引擎
|
||||
|
||||
// 第四步: 加载共享库 & JS 处理器
|
||||
err = share.Load(cfg) // 加载共享库 lib
|
||||
// Load Query Engine
|
||||
err = query.Load(cfg)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Lib", err)
|
||||
printErr(cfg.Mode, "Query Engine", err)
|
||||
}
|
||||
|
||||
err = script.Load(cfg) // 加载JS处理器 script
|
||||
// Load Scripts
|
||||
err = script.Load(cfg)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Script", err)
|
||||
}
|
||||
|
||||
// 第五步: 加载数据模型等
|
||||
err = model.Load(cfg) // 加载数据模型 model
|
||||
// Load Models
|
||||
err = model.Load(cfg)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Model", err)
|
||||
}
|
||||
|
||||
err = flow.Load(cfg) // 加载业务逻辑 Flow
|
||||
// Load Data flows
|
||||
err = flow.Load(cfg)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Flow", err)
|
||||
}
|
||||
|
||||
err = store.Load(cfg) // Load stores
|
||||
// Load Stores
|
||||
err = store.Load(cfg)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Store", err)
|
||||
}
|
||||
|
||||
err = plugin.Load(cfg) // 加载业务插件 plugin
|
||||
// Load Plugins
|
||||
err = plugin.Load(cfg)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Plugin", err)
|
||||
}
|
||||
|
||||
// // XGEN 1.0
|
||||
// if share.App.XGen == "1.0" {
|
||||
// Load WASM Application (experimental)
|
||||
|
||||
// // SET XGEN_BASE
|
||||
// // adminRoot := "yao"
|
||||
// // if share.App.Optional != nil {
|
||||
// // if root, has := share.App.Optional["adminRoot"]; has {
|
||||
// // adminRoot = fmt.Sprintf("%v", root)
|
||||
// // }
|
||||
// // }
|
||||
// // os.Setenv("XGEN_BASE", adminRoot)
|
||||
// Load build-in widgets (table / form / chart / ...)
|
||||
err = widgets.Load(cfg)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Widgets", err)
|
||||
}
|
||||
|
||||
// // Load build-in widgets
|
||||
// err = widgets.Load(cfg)
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Widgets", err)
|
||||
// }
|
||||
|
||||
// delete(gou.APIs, "xiang.table")
|
||||
// delete(gou.APIs, "xiang.page")
|
||||
// delete(gou.APIs, "xiang.chart")
|
||||
// delete(gou.APIs, "xiang.xiang")
|
||||
// delete(gou.APIs, "xiang.user")
|
||||
// delete(gou.APIs, "xiang.storage")
|
||||
|
||||
// } else { // old version
|
||||
// err = table.Load(cfg) // 加载数据表格 table
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Table", err)
|
||||
// }
|
||||
|
||||
// err = chart.Load(cfg) // 加载分析图表 chart
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Chart", err)
|
||||
// }
|
||||
|
||||
// err = page.Load(cfg) // 加载页面 page 忽略错误
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Page", err)
|
||||
// }
|
||||
// }
|
||||
|
||||
importer.Load(cfg) // 加载数据导入 imports
|
||||
// Load Importers
|
||||
err = importer.Load(cfg)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Plugin", err)
|
||||
}
|
||||
|
||||
// Load Apis
|
||||
err = api.Load(cfg) // 加载业务接口 API
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "API", err)
|
||||
}
|
||||
|
||||
// Load Sockets
|
||||
err = socket.Load(cfg) // Load sockets
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Socket", err)
|
||||
}
|
||||
|
||||
err = websocket.Load(cfg) // Load websockets (client)
|
||||
// Load websockets (client mode)
|
||||
err = websocket.Load(cfg)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "WebSocket", err)
|
||||
}
|
||||
|
||||
err = task.Load(cfg) // Load tasks
|
||||
// Load tasks
|
||||
err = task.Load(cfg)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Task", err)
|
||||
}
|
||||
|
||||
err = schedule.Load(cfg) // Load schedules
|
||||
// Load schedules
|
||||
err = schedule.Load(cfg)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Schedule", err)
|
||||
}
|
||||
|
||||
err = widget.Load(cfg) // Load widgets
|
||||
// Load Custom Widget
|
||||
err = widget.Load(cfg)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Widget", err)
|
||||
}
|
||||
|
|
@ -207,6 +176,78 @@ func Load(cfg config.Config) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Unload application engine
|
||||
func Unload() (err error) {
|
||||
defer func() { err = exception.Catch(recover()) }()
|
||||
|
||||
// Close DB
|
||||
err = share.DBClose()
|
||||
|
||||
// Stop Runtime
|
||||
err = runtime.Stop()
|
||||
|
||||
// Recycle
|
||||
// api
|
||||
// models
|
||||
// flows
|
||||
// stores
|
||||
// scripts
|
||||
// connectors
|
||||
// filesystem
|
||||
// i18n
|
||||
// certs
|
||||
// plugins
|
||||
// importers
|
||||
// tasks
|
||||
// schedules
|
||||
// sockets
|
||||
// websockets
|
||||
// widgets
|
||||
// custom widget
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload the application engine
|
||||
func Reload(cfg config.Config) error {
|
||||
err := Unload()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return Load(cfg)
|
||||
}
|
||||
|
||||
// loadApp load the application from bindata / pkg / disk
|
||||
func loadApp(root string) error {
|
||||
|
||||
var err error
|
||||
var app application.Application
|
||||
|
||||
if root == "bin:application.pkg" {
|
||||
app, err = application.OpenFromBin(root, &share.Pack{}) // Load app from Bin
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
application.Load(app)
|
||||
|
||||
} else if strings.HasSuffix(root, ".pkg") {
|
||||
|
||||
app, err = application.OpenFromPkg(root, &share.Pack{}) // Load app from .pkg file
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
application.Load(app)
|
||||
}
|
||||
|
||||
app, err = application.OpenFromDisk(root) // Load app from Disk
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
application.Load(app)
|
||||
return nil
|
||||
}
|
||||
|
||||
func printErr(mode, widget string, err error) {
|
||||
message := fmt.Sprintf("[%s] %s", widget, err.Error())
|
||||
if !strings.Contains(message, "does not exists") && mode == "development" {
|
||||
|
|
@ -214,53 +255,230 @@ func printErr(mode, widget string, err error) {
|
|||
}
|
||||
}
|
||||
|
||||
// // LoadDeprecated 根据配置加载 API, FLow, Model, Plugin
|
||||
// func LoadDeprecated(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)
|
||||
|
||||
// // 加密密钥函数
|
||||
// // model.LoadCrypt(fmt.Sprintf(`{"key":"%s"}`, cfg.DB.AESKey), "AES")
|
||||
// // gou.LoadCrypt(`{}`, "PASSWORD")
|
||||
|
||||
// // Load Certs
|
||||
// err = cert.Load(cfg)
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Cert", err)
|
||||
// }
|
||||
|
||||
// // Load connectors
|
||||
// err = connector.Load(cfg)
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Connector", err)
|
||||
// }
|
||||
|
||||
// // Load FileSystem
|
||||
// err = fs.Load(cfg)
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "FileSystem", err)
|
||||
// }
|
||||
|
||||
// // Load i18n
|
||||
// err = i18n.Load(cfg)
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "i18n", err)
|
||||
// }
|
||||
|
||||
// // Load Studio development mode only
|
||||
// if cfg.Mode == "development" {
|
||||
// err = studio.Load(cfg)
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Studio", err)
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 第二步: 建立数据库 & 会话连接
|
||||
// err = share.DBConnect(cfg.DB) // 创建数据库连接
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "DB", err)
|
||||
// }
|
||||
|
||||
// // share.SessionConnect(cfg.Session) // 创建会话服务器链接
|
||||
|
||||
// // 加载应用引擎
|
||||
// if os.Getenv("YAO_DEV") != "" {
|
||||
// LoadEngine(filepath.Join(os.Getenv("YAO_DEV"), "/yao"))
|
||||
// } else {
|
||||
// LoadEngine()
|
||||
// }
|
||||
|
||||
// // 第三步: 加载数据分析引擎
|
||||
// query.Load(cfg) // 加载数据分析引擎
|
||||
|
||||
// // 第四步: 加载共享库 & JS 处理器
|
||||
// err = share.Load(cfg) // 加载共享库 lib
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Lib", err)
|
||||
// }
|
||||
|
||||
// err = script.Load(cfg) // 加载JS处理器 script
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Script", err)
|
||||
// }
|
||||
|
||||
// // 第五步: 加载数据模型等
|
||||
// err = model.Load(cfg) // 加载数据模型 model
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Model", err)
|
||||
// }
|
||||
|
||||
// err = flow.Load(cfg) // 加载业务逻辑 Flow
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Flow", err)
|
||||
// }
|
||||
|
||||
// err = store.Load(cfg) // Load stores
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Store", err)
|
||||
// }
|
||||
|
||||
// err = plugin.Load(cfg) // 加载业务插件 plugin
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Plugin", err)
|
||||
// }
|
||||
|
||||
// // // XGEN 1.0
|
||||
// // if share.App.XGen == "1.0" {
|
||||
|
||||
// // // SET XGEN_BASE
|
||||
// // // adminRoot := "yao"
|
||||
// // // if share.App.Optional != nil {
|
||||
// // // if root, has := share.App.Optional["adminRoot"]; has {
|
||||
// // // adminRoot = fmt.Sprintf("%v", root)
|
||||
// // // }
|
||||
// // // }
|
||||
// // // os.Setenv("XGEN_BASE", adminRoot)
|
||||
|
||||
// // // Load build-in widgets
|
||||
// // err = widgets.Load(cfg)
|
||||
// // if err != nil {
|
||||
// // printErr(cfg.Mode, "Widgets", err)
|
||||
// // }
|
||||
|
||||
// // delete(gou.APIs, "xiang.table")
|
||||
// // delete(gou.APIs, "xiang.page")
|
||||
// // delete(gou.APIs, "xiang.chart")
|
||||
// // delete(gou.APIs, "xiang.xiang")
|
||||
// // delete(gou.APIs, "xiang.user")
|
||||
// // delete(gou.APIs, "xiang.storage")
|
||||
|
||||
// // } else { // old version
|
||||
// // err = table.Load(cfg) // 加载数据表格 table
|
||||
// // if err != nil {
|
||||
// // printErr(cfg.Mode, "Table", err)
|
||||
// // }
|
||||
|
||||
// // err = chart.Load(cfg) // 加载分析图表 chart
|
||||
// // if err != nil {
|
||||
// // printErr(cfg.Mode, "Chart", err)
|
||||
// // }
|
||||
|
||||
// // err = page.Load(cfg) // 加载页面 page 忽略错误
|
||||
// // if err != nil {
|
||||
// // printErr(cfg.Mode, "Page", err)
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// importer.Load(cfg) // 加载数据导入 imports
|
||||
|
||||
// err = api.Load(cfg) // 加载业务接口 API
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "API", err)
|
||||
// }
|
||||
|
||||
// err = socket.Load(cfg) // Load sockets
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Socket", err)
|
||||
// }
|
||||
|
||||
// err = websocket.Load(cfg) // Load websockets (client)
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "WebSocket", err)
|
||||
// }
|
||||
|
||||
// err = task.Load(cfg) // Load tasks
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Task", err)
|
||||
// }
|
||||
|
||||
// err = schedule.Load(cfg) // Load schedules
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Schedule", err)
|
||||
// }
|
||||
|
||||
// err = widget.Load(cfg) // Load widgets
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Widget", err)
|
||||
// }
|
||||
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// Reload 根据配置重新加载 API, FLow, Model, Plugin
|
||||
func Reload(cfg config.Config) {
|
||||
// gou.APIs = map[string]*gou.API{}
|
||||
// gou.Models = map[string]*gou.Model{}
|
||||
// gou.Flows = map[string]*gou.Flow{}
|
||||
// gou.Plugins = map[string]*gou.Plugin{}
|
||||
Load(cfg)
|
||||
}
|
||||
// func Reload(cfg config.Config) {
|
||||
// gou.APIs = map[string]*gou.API{}
|
||||
// gou.Models = map[string]*gou.Model{}
|
||||
// gou.Flows = map[string]*gou.Flow{}
|
||||
// gou.Plugins = map[string]*gou.Plugin{}
|
||||
// Load(cfg)
|
||||
// }
|
||||
|
||||
// LoadEngine 加载引擎的 API, Flow, Model 配置
|
||||
func LoadEngine(from ...string) {
|
||||
// var scripts []share.Script
|
||||
// if len(from) > 0 {
|
||||
// scripts = share.GetFilesFS(from[0], ".json")
|
||||
// } else {
|
||||
// scripts = share.GetFilesBin("yao", ".json")
|
||||
// }
|
||||
// func LoadEngine(from ...string) {
|
||||
// var scripts []share.Script
|
||||
// if len(from) > 0 {
|
||||
// scripts = share.GetFilesFS(from[0], ".json")
|
||||
// } else {
|
||||
// scripts = share.GetFilesBin("yao", ".json")
|
||||
// }
|
||||
|
||||
// if scripts == nil {
|
||||
// exception.New("读取文件失败", 500, from).Throw()
|
||||
// }
|
||||
// if scripts == nil {
|
||||
// exception.New("读取文件失败", 500, from).Throw()
|
||||
// }
|
||||
|
||||
// if len(scripts) == 0 {
|
||||
// exception.New("读取文件失败, 未找到任何可执行脚本", 500, from).Throw()
|
||||
// }
|
||||
// if len(scripts) == 0 {
|
||||
// exception.New("读取文件失败, 未找到任何可执行脚本", 500, from).Throw()
|
||||
// }
|
||||
|
||||
// // 加载 API, Flow, Models, Table, Chart, Screens
|
||||
// for _, script := range scripts {
|
||||
// switch script.Type {
|
||||
// case "models":
|
||||
// gou.LoadModel(string(script.Content), "xiang."+script.Name)
|
||||
// break
|
||||
// case "flows":
|
||||
// gou.LoadFlow(string(script.Content), "xiang."+script.Name)
|
||||
// break
|
||||
// case "apis":
|
||||
// gou.LoadAPI(string(script.Content), "xiang."+script.Name)
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// // 加载 API, Flow, Models, Table, Chart, Screens
|
||||
// for _, script := range scripts {
|
||||
// switch script.Type {
|
||||
// case "models":
|
||||
// gou.LoadModel(string(script.Content), "xiang."+script.Name)
|
||||
// break
|
||||
// case "flows":
|
||||
// gou.LoadFlow(string(script.Content), "xiang."+script.Name)
|
||||
// break
|
||||
// case "apis":
|
||||
// gou.LoadAPI(string(script.Content), "xiang."+script.Name)
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 加载数据应用
|
||||
// for _, script := range scripts {
|
||||
// switch script.Type {
|
||||
// case "tables":
|
||||
// table.LoadTable(string(script.Content), "xiang."+script.Name)
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
}
|
||||
// // 加载数据应用
|
||||
// for _, script := range scripts {
|
||||
// switch script.Type {
|
||||
// case "tables":
|
||||
// table.LoadTable(string(script.Content), "xiang."+script.Name)
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -1,35 +1,26 @@
|
|||
package engine
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou/api"
|
||||
"github.com/yaoapp/yao/config"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
defer Load(config.Conf)
|
||||
assert.NotPanics(t, func() {
|
||||
Load(config.Conf)
|
||||
})
|
||||
defer Unload()
|
||||
err := Load(config.Conf)
|
||||
assert.Nil(t, err)
|
||||
assert.Greater(t, len(api.APIs), 0)
|
||||
}
|
||||
|
||||
// 从文件系统载入引擎文件
|
||||
func TestLoadEngineFS(t *testing.T) {
|
||||
defer Load(config.Conf)
|
||||
root := path.Join(os.Getenv("YAO_DEV"), "/yao")
|
||||
assert.NotPanics(t, func() {
|
||||
LoadEngine(root)
|
||||
})
|
||||
func TestReload(t *testing.T) {
|
||||
defer Unload()
|
||||
err := Load(config.Conf)
|
||||
assert.Nil(t, err)
|
||||
|
||||
}
|
||||
|
||||
// 从BinDataz载入引擎文件
|
||||
func TestLoadEngineBin(t *testing.T) {
|
||||
defer Load(config.Conf)
|
||||
assert.NotPanics(t, func() {
|
||||
LoadEngine()
|
||||
})
|
||||
Reload(config.Conf)
|
||||
assert.Nil(t, err)
|
||||
assert.Greater(t, len(api.APIs), 0)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
|
|
@ -30,8 +33,11 @@ func processPing(process *process.Process) interface{} {
|
|||
|
||||
// processInspect 返回系统信息
|
||||
func processInspect(process *process.Process) interface{} {
|
||||
share.App.Icons.Set("favicon", "/api/xiang/favicon.ico")
|
||||
return share.App.Public()
|
||||
return map[string]interface{}{
|
||||
"VERSION": fmt.Sprintf("%s %s", share.VERSION, share.PRVERSION),
|
||||
"BUILDNAME": share.BUILDNAME,
|
||||
"CONFIG": config.Conf,
|
||||
}
|
||||
}
|
||||
|
||||
// processFavicon 运行模型 MustCreate
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ func TestProcessAliasPing(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProcessInspect(t *testing.T) {
|
||||
res, ok := process.New("xiang.sys.Inspect").Run().(share.AppInfo)
|
||||
res, ok := process.New("xiang.sys.Inspect").Run().(map[string]interface{})
|
||||
assert.True(t, ok)
|
||||
assert.NotNil(t, res.Version)
|
||||
assert.NotNil(t, res["VERSION"])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
// Load 加载查询引擎
|
||||
func Load(cfg config.Config) {
|
||||
func Load(cfg config.Config) error {
|
||||
|
||||
if _, has := query.Engines["default"]; !has {
|
||||
registerDefault()
|
||||
|
|
@ -36,6 +36,8 @@ func Load(cfg config.Config) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// registerDefaultQuery register the default engine
|
||||
|
|
|
|||
18
share/pack.go
Normal file
18
share/pack.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package share
|
||||
|
||||
// ********************************************************************************
|
||||
// WARNING: DO NOT MODIFY THIS FILE. IT WILL BE REPLACED BY THE APPLICATION CODE.
|
||||
// *********************************************************************************
|
||||
|
||||
// Pack the yao app package
|
||||
type Pack struct{}
|
||||
|
||||
// Decode the package decode method
|
||||
func (pkg *Pack) Decode(data []byte) ([]byte, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Encode the package encode method
|
||||
func (pkg *Pack) Encode(data []byte) ([]byte, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
|
@ -34,8 +34,7 @@ func Prepare(t *testing.T, cfg config.Config) {
|
|||
var err error
|
||||
|
||||
if root == "bin:application.pkg" {
|
||||
key := os.Getenv("YAO_TEST_PRIVATE_KEY")
|
||||
app, err = application.OpenFromBin(root, key) // Load app from Bin
|
||||
app, err = application.OpenFromBin(root, &share.Pack{}) // Load app from Bin
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue