Skip to content

Commit

Permalink
调整环境变量
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Feb 8, 2022
1 parent f42b0ca commit ea72f26
Show file tree
Hide file tree
Showing 57 changed files with 779 additions and 637 deletions.
52 changes: 33 additions & 19 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,50 @@ on:
branches: [main]

env:
YAO_DEV: ${{ github.WORKSPACE }}
YAO_ENV: development
YAO_ROOT: ${{ github.WORKSPACE }}/tests
YAO_HOST: 0.0.0.0
YAO_PORT: 5099
YAO_SESSION: "memory"
YAO_LOG: "./logs/application.log"
YAO_LOG_MODE: "TEXT"
YAO_JWT_SECRET: "bLp@bi!oqo-2U+hoTRUG"
YAO_DB_DRIVER: mysql
YAO_DB_PRIMARY: "root:123456@tcp(db-server:3308)/xiang?charset=utf8mb4&parseTime=True&loc=Local"
YAO_DB_SECONDARY: "root:123456@tcp(db-server:3308)/xiang?charset=utf8mb4&parseTime=True&loc=Local"
YAO_DB_AESKEY: "ZLX=T&f6refeCh-ro*r@"

# 象传服务配置
XIANG_MODE: debug
XIANG_SOURCE: ${{ github.WORKSPACE }}
XIANG_ROOT: ${{ github.WORKSPACE }}/tests
XIANG_ROOT_PLUGIN: ${{ github.WORKSPACE }}/../../../data/gou-unit/plugins
# XIANG_MODE: debug
# XIANG_SOURCE: ${{ github.WORKSPACE }}
# XIANG_ROOT: ${{ github.WORKSPACE }}/tests
# XIANG_ROOT_PLUGIN: ${{ github.WORKSPACE }}/../../../data/gou-unit/plugins

# 服务配置
XIANG_SERVICE_DEBUG: true
XIANG_SERVICE_ALLOW: "xiang.yao.run:3000|xiang.yao.run:3001"
XIANG_SERVICE_HOST: 0.0.0.0
XIANG_SERVICE_PORT: 5099
# XIANG_SERVICE_DEBUG: true
# XIANG_SERVICE_ALLOW: "xiang.yao.run:3000|xiang.yao.run:3001"
# XIANG_SERVICE_HOST: 0.0.0.0
# XIANG_SERVICE_PORT: 5099

# 数据库配置
XIANG_DB_DEBUG: true
XIANG_DB_DRIVER: "mysql"
XIANG_DB_AESKEY: "ZLX:XzT&f6refeCh-ro*r@"
# XIANG_DB_DEBUG: true
# XIANG_DB_DRIVER: "mysql"
# XIANG_DB_AESKEY: "ZLX:XzT&f6refeCh-ro*r@"

# JWT配置
XIANG_JWT_DEBUG: true
XIANG_JWT_SECRET: "bLp@bi!oqo-2U+hoTRUG"
# XIANG_JWT_DEBUG: true
# XIANG_JWT_SECRET: "bLp@bi!oqo-2U+hoTRUG"

# 存储配置
XIANG_STOR_DEBUG: true
XIANG_STOR_PATH: "fs://${{ github.WORKSPACE }}/upload"
# XIANG_STOR_DEBUG: true
# XIANG_STOR_PATH: "fs://${{ github.WORKSPACE }}/upload"

# 日志配置
XIANG_LOG_ACCESS: "fs://${{ github.WORKSPACE }}/logs/access.log"
XIANG_LOG_ERROR: "fs://${{ github.WORKSPACE }}/logs/error.log"
XIANG_LOG_DB: "fs://${{ github.WORKSPACE }}/logs/db.log"
XIANG_LOG_PLUGIN: "fs://${{ github.WORKSPACE }}/logs/plugin.log"
# XIANG_LOG_ACCESS: "fs://${{ github.WORKSPACE }}/logs/access.log"
# XIANG_LOG_ERROR: "fs://${{ github.WORKSPACE }}/logs/error.log"
# XIANG_LOG_DB: "fs://${{ github.WORKSPACE }}/logs/db.log"
# XIANG_LOG_PLUGIN: "fs://${{ github.WORKSPACE }}/logs/plugin.log"

jobs:
unit-test:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ ui
tests/data/*/*
debug.log
yao-test
dev.sh
30 changes: 22 additions & 8 deletions api/api.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
package api

import (
"fmt"
"path/filepath"

"github.com/yaoapp/gou"
"github.com/yaoapp/kun/log"
"github.com/yaoapp/xiang/config"
"github.com/yaoapp/xiang/share"
)

// Load 加载API
func Load(cfg config.Config) {
LoadFrom(cfg.RootAPI, "")
func Load(cfg config.Config) error {
if share.BUILDIN {
return LoadBuildIn("apis", "")
}
return LoadFrom(filepath.Join(cfg.Root, "apis"), "")
}

// LoadFrom 从特定目录加载
func LoadFrom(dir string, prefix string) {

func LoadFrom(dir string, prefix string) error {
if share.DirNotExists(dir) {
return
return fmt.Errorf("%s does not exists", dir)
}

share.Walk(dir, ".http.json", func(root, filename string) {
err := share.Walk(dir, ".http.json", func(root, filename string) {
name := prefix + share.SpecName(root, filename)
content := share.ReadFile(filename)
gou.LoadAPI(string(content), name)
_, err := gou.LoadAPIReturn(string(content), name)
if err != nil {
log.With(log.F{"root": root, "file": filename}).Error(err.Error())
}
})
return err
}

// LoadBuildIn 从制品中读取
func LoadBuildIn(dir string, prefix string) error {
return nil
}
81 changes: 38 additions & 43 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package app

import (
"io/ioutil"
"os"
"path/filepath"

jsoniter "github.com/json-iterator/go"
"github.com/yaoapp/kun/exception"
"github.com/yaoapp/kun/maps"
"github.com/yaoapp/xiang/config"
"github.com/yaoapp/xiang/data"
"github.com/yaoapp/xiang/share"
"github.com/yaoapp/xiang/xfs"
"github.com/yaoapp/xiang/xlog"
)

// Load 加载应用信息
Expand All @@ -24,44 +19,44 @@ func Load(cfg config.Config) {
// Init 应用初始化
func Init(cfg config.Config) {

// UI文件目录
if _, err := os.Stat(cfg.RootUI); os.IsNotExist(err) {
err := os.MkdirAll(cfg.RootUI, os.ModePerm)
if err != nil {
xlog.Printf("创建目录失败(%s) %s", cfg.RootUI, err)
os.Exit(1)
}

content, err := data.Asset("xiang/data/index.html")
if err != nil {
xlog.Printf("读取文件失败(%s) %s", cfg.RootUI, err)
os.Exit(1)
}

err = ioutil.WriteFile(filepath.Join(cfg.RootUI, "/index.html"), content, os.ModePerm)
if err != nil {
xlog.Printf("复制默认文件失败(%s) %s", cfg.RootUI, err)
os.Exit(1)
}
}

// 数据库目录
if _, err := os.Stat(cfg.RootDB); os.IsNotExist(err) {
err := os.MkdirAll(cfg.RootDB, os.ModePerm)
if err != nil {
xlog.Printf("创建目录失败(%s) %s", cfg.RootDB, err)
os.Exit(1)
}
}

// 文件数据目录
if _, err := os.Stat(cfg.RootData); os.IsNotExist(err) {
err := os.MkdirAll(cfg.RootData, os.ModePerm)
if err != nil {
xlog.Printf("创建目录失败(%s) %s", cfg.RootData, err)
os.Exit(1)
}
}
// // UI文件目录
// if _, err := os.Stat(cfg.RootUI); os.IsNotExist(err) {
// err := os.MkdirAll(cfg.RootUI, os.ModePerm)
// if err != nil {
// xlog.Printf("创建目录失败(%s) %s", cfg.RootUI, err)
// os.Exit(1)
// }

// content, err := data.Asset("xiang/data/index.html")
// if err != nil {
// xlog.Printf("读取文件失败(%s) %s", cfg.RootUI, err)
// os.Exit(1)
// }

// err = ioutil.WriteFile(filepath.Join(cfg.RootUI, "/index.html"), content, os.ModePerm)
// if err != nil {
// xlog.Printf("复制默认文件失败(%s) %s", cfg.RootUI, err)
// os.Exit(1)
// }
// }

// // 数据库目录
// if _, err := os.Stat(cfg.RootDB); os.IsNotExist(err) {
// err := os.MkdirAll(cfg.RootDB, os.ModePerm)
// if err != nil {
// xlog.Printf("创建目录失败(%s) %s", cfg.RootDB, err)
// os.Exit(1)
// }
// }

// // 文件数据目录
// if _, err := os.Stat(cfg.RootData); os.IsNotExist(err) {
// err := os.MkdirAll(cfg.RootData, os.ModePerm)
// if err != nil {
// xlog.Printf("创建目录失败(%s) %s", cfg.RootData, err)
// os.Exit(1)
// }
// }
}

// LoadInfo 应用信息
Expand Down
35 changes: 24 additions & 11 deletions chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,54 @@ package chart

import (
"fmt"
"path/filepath"

jsoniter "github.com/json-iterator/go"
"github.com/yaoapp/gou"
"github.com/yaoapp/kun/exception"
"github.com/yaoapp/kun/log"
"github.com/yaoapp/xiang/config"
"github.com/yaoapp/xiang/share"
"github.com/yaoapp/xiang/xlog"
)

// Charts 已载入图表
var Charts = map[string]*Chart{}

// Load 加载数据表格
func Load(cfg config.Config) {
LoadFrom(cfg.RootChart, "")
func Load(cfg config.Config) error {
if share.BUILDIN {
return LoadBuildIn("charts", "")
}
return LoadFrom(filepath.Join(cfg.Root, "charts"), "")
}

// LoadBuildIn 从制品中读取
func LoadBuildIn(dir string, prefix string) error {
return nil
}

// LoadFrom 从特定目录加载
func LoadFrom(dir string, prefix string) {
func LoadFrom(dir string, prefix string) error {

if share.DirNotExists(dir) {
return
return fmt.Errorf("%s does not exists", dir)
}

share.Walk(dir, ".json", func(root, filename string) {
err := share.Walk(dir, ".json", func(root, filename string) {
name := prefix + share.SpecName(root, filename)
content := share.ReadFile(filename)
_, err := LoadChart(content, name)
if err != nil {
exception.New("%s 图表格式错误", 400, name).Ctx(filename).Throw()
log.With(log.F{"root": root, "file": filename}).Error(err.Error())
}
})

if err != nil {
return err
}

// Load Script
share.Walk(dir, ".js", func(root, filename string) {
err = share.Walk(dir, ".js", func(root, filename string) {
name := prefix + share.SpecName(root, filename)
chart := Select(name)
if chart != nil {
Expand All @@ -45,6 +58,8 @@ func LoadFrom(dir string, prefix string) {
chart.LoadScript(string(content), script)
}
})

return err
}

// LoadChart 载入数据表格
Expand All @@ -56,9 +71,7 @@ func LoadChart(source []byte, name string) (*Chart, error) {
}
err := jsoniter.Unmarshal(source, chart)
if err != nil {
xlog.Println(name)
xlog.Println(err.Error())
xlog.Println(string(source))
log.With(log.F{"name": name, "source": source}).Error(err.Error())
return nil, err
}
chart.Prepare()
Expand Down
2 changes: 1 addition & 1 deletion chart/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestLoad(t *testing.T) {
share.DBConnect(config.Conf.Database)
share.DBConnect(config.Conf.DB)
model.Load(config.Conf)
query.Load(config.Conf)

Expand Down
2 changes: 1 addition & 1 deletion chart/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func init() {
share.DBConnect(config.Conf.Database)
share.DBConnect(config.Conf.DB)
model.Load(config.Conf)
query.Load(config.Conf)
Load(config.Conf)
Expand Down
18 changes: 0 additions & 18 deletions cmd/domain.go

This file was deleted.

1 change: 0 additions & 1 deletion cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var inspectCmd = &cobra.Command{
Boot()
res := maps.Map{
"version": share.VERSION,
"domain": share.DOMAIN,
"config": config.Conf,
}
utils.Dump(res)
Expand Down
15 changes: 8 additions & 7 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ var rootCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(
versionCmd,
// domainCmd,
migrateCmd,
inspectCmd,
startCmd,
// importCmd,
runCmd,
)
rootCmd.SetHelpCommand(helpCmd)
Expand All @@ -54,15 +52,18 @@ func Execute() {
func Boot() {

if envFile == "" && appPath != "" {
config.SetAppPath(appPath, filepath.Join(appPath, ".env"))
config.Conf = config.LoadFrom(filepath.Join(appPath, ".env"))
config.Conf.Root = appPath
return
}

if envFile != "" { // 指定环境变量文件
config.SetEnvFile(envFile)
if envFile != "" && appPath == "" { // 指定环境变量文件
// config.SetEnvFile(envFile)
config.Conf = config.LoadFrom(envFile)
}

if appPath != "" {
config.SetAppPath(appPath)
if envFile != "" && appPath != "" {
config.Conf = config.LoadFrom(envFile)
config.Conf.Root = appPath
}
}
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var runCmd = &cobra.Command{
defer gou.KillPlugins()
Boot()
cfg := config.Conf
cfg.Session.IsCLI = true
// cfg.Session.IsCLI = true
engine.Load(cfg)
if len(args) < 1 {
fmt.Println(color.RedString("参数错误: 未指定处理名称"))
Expand Down
Loading

0 comments on commit ea72f26

Please sign in to comment.