[add] load application from the package file
This commit is contained in:
parent
68e009ad06
commit
49430cf5b3
4 changed files with 76 additions and 17 deletions
|
|
@ -14,6 +14,7 @@ import (
|
||||||
|
|
||||||
var appPath string
|
var appPath string
|
||||||
var envFile string
|
var envFile string
|
||||||
|
var yazFile string
|
||||||
|
|
||||||
var lang = os.Getenv("YAO_LANG")
|
var lang = os.Getenv("YAO_LANG")
|
||||||
var langs = map[string]string{
|
var langs = map[string]string{
|
||||||
|
|
@ -128,6 +129,7 @@ func init() {
|
||||||
)
|
)
|
||||||
// rootCmd.SetHelpCommand(helpCmd)
|
// rootCmd.SetHelpCommand(helpCmd)
|
||||||
rootCmd.PersistentFlags().StringVarP(&appPath, "app", "a", "", L("Application directory"))
|
rootCmd.PersistentFlags().StringVarP(&appPath, "app", "a", "", L("Application directory"))
|
||||||
|
rootCmd.PersistentFlags().StringVarP(&yazFile, "file", "f", "", L("Application package file"))
|
||||||
rootCmd.PersistentFlags().StringVarP(&envFile, "env", "e", "", L("Environment file"))
|
rootCmd.PersistentFlags().StringVarP(&envFile, "env", "e", "", L("Environment file"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,6 +144,7 @@ func Execute() {
|
||||||
// Boot 设定配置
|
// Boot 设定配置
|
||||||
func Boot() {
|
func Boot() {
|
||||||
root := config.Conf.Root
|
root := config.Conf.Root
|
||||||
|
|
||||||
if appPath != "" {
|
if appPath != "" {
|
||||||
r, err := filepath.Abs(appPath)
|
r, err := filepath.Abs(appPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -149,12 +152,17 @@ func Boot() {
|
||||||
}
|
}
|
||||||
root = r
|
root = r
|
||||||
}
|
}
|
||||||
|
|
||||||
if envFile != "" {
|
if envFile != "" {
|
||||||
config.Conf = config.LoadFrom(envFile)
|
config.Conf = config.LoadFrom(envFile)
|
||||||
} else {
|
} else {
|
||||||
config.Conf = config.LoadFrom(filepath.Join(root, ".env"))
|
config.Conf = config.LoadFrom(filepath.Join(root, ".env"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if yazFile != "" {
|
||||||
|
config.Conf.AppSource = yazFile
|
||||||
|
}
|
||||||
|
|
||||||
if config.Conf.Mode == "production" {
|
if config.Conf.Mode == "production" {
|
||||||
config.Production()
|
config.Production()
|
||||||
} else if config.Conf.Mode == "development" {
|
} else if config.Conf.Mode == "development" {
|
||||||
|
|
|
||||||
|
|
@ -225,28 +225,27 @@ func loadApp(root string) error {
|
||||||
var err error
|
var err error
|
||||||
var app application.Application
|
var app application.Application
|
||||||
|
|
||||||
if root == "bin:application.pkg" {
|
if root == "bin:application.yaz" {
|
||||||
app, err = application.OpenFromBin(root, &share.Pack{}) // Load app from Bin
|
app, err = application.OpenFromYaz(root, &share.Pack{}) // Load app from Bin
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
application.Load(app)
|
application.Load(app)
|
||||||
|
|
||||||
} else if strings.HasSuffix(root, ".pkg") {
|
} else if strings.HasSuffix(root, ".yaz") {
|
||||||
|
app, err = application.OpenFromYaz(root, &share.Pack{}) // Load app from .yaz file
|
||||||
app, err = application.OpenFromPkg(root, &share.Pack{}) // Load app from .pkg file
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
application.Load(app)
|
application.Load(app)
|
||||||
}
|
|
||||||
|
|
||||||
|
} else {
|
||||||
app, err = application.OpenFromDisk(root) // Load app from Disk
|
app, err = application.OpenFromDisk(root) // Load app from Disk
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
application.Load(app)
|
application.Load(app)
|
||||||
|
}
|
||||||
|
|
||||||
var info []byte
|
var info []byte
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
package engine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/yaoapp/gou/api"
|
"github.com/yaoapp/gou/api"
|
||||||
|
"github.com/yaoapp/gou/application/yaz"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
|
"github.com/yaoapp/yao/share"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoad(t *testing.T) {
|
func TestLoad(t *testing.T) {
|
||||||
|
|
@ -24,3 +27,48 @@ func TestReload(t *testing.T) {
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Greater(t, len(api.APIs), 0)
|
assert.Greater(t, len(api.APIs), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoadYaz(t *testing.T) {
|
||||||
|
|
||||||
|
defer Unload()
|
||||||
|
|
||||||
|
// package yaz
|
||||||
|
file, err := yaz.Pack(config.Conf.Root, &share.Pack{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.Remove(file)
|
||||||
|
|
||||||
|
cfg := config.Conf
|
||||||
|
cfg.AppSource = file
|
||||||
|
err = Load(cfg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
assert.Greater(t, len(api.APIs), 0)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReoadYaz(t *testing.T) {
|
||||||
|
|
||||||
|
defer Unload()
|
||||||
|
|
||||||
|
// package yaz
|
||||||
|
file, err := yaz.Pack(config.Conf.Root, &share.Pack{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.Remove(file)
|
||||||
|
|
||||||
|
cfg := config.Conf
|
||||||
|
cfg.AppSource = file
|
||||||
|
err = Load(cfg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
assert.Greater(t, len(api.APIs), 0)
|
||||||
|
|
||||||
|
Reload(cfg)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Greater(t, len(api.APIs), 0)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package share
|
package share
|
||||||
|
|
||||||
|
import "io"
|
||||||
|
|
||||||
// ********************************************************************************
|
// ********************************************************************************
|
||||||
// WARNING: DO NOT MODIFY THIS FILE. IT WILL BE REPLACED BY THE APPLICATION CODE.
|
// WARNING: DO NOT MODIFY THIS FILE. IT WILL BE REPLACED BY THE APPLICATION CODE.
|
||||||
// *********************************************************************************
|
// *********************************************************************************
|
||||||
|
|
@ -7,12 +9,14 @@ package share
|
||||||
// Pack the yao app package
|
// Pack the yao app package
|
||||||
type Pack struct{}
|
type Pack struct{}
|
||||||
|
|
||||||
// Decode the package decode method
|
// Encrypt encrypt
|
||||||
func (pkg *Pack) Decode(data []byte) ([]byte, error) {
|
func (pkg *Pack) Encrypt(reader io.Reader, writer io.Writer) error {
|
||||||
return data, nil
|
_, err := io.Copy(writer, reader)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode the package encode method
|
// Decrypt decrypt
|
||||||
func (pkg *Pack) Encode(data []byte) ([]byte, error) {
|
func (pkg *Pack) Decrypt(reader io.Reader, writer io.Writer) error {
|
||||||
return data, nil
|
_, err := io.Copy(writer, reader)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue