Merge branch 'dev_v3' into test_v3

This commit is contained in:
gaoshuaixing
2023-11-24 18:31:10 +08:00
14 changed files with 272 additions and 74 deletions

3
.gitignore vendored
View File

@@ -10,3 +10,6 @@ public/electron/
pnpm-lock.yaml
.yalc/
yalc.lock
go/public/
build/extraResources/core.exe
build/extraResources/goapp.exe

View File

@@ -21,27 +21,67 @@ module.exports = {
directory: './',
cmd: 'electron',
args: ['.', '--env=local'],
},
go: {
directory: './go',
cmd: 'go',
args: ['run', './main.go', '--env=dev','--basedir=../', '--port=7073'],
},
},
/**
* 构建
* ee-bin build
*/
build: {
frontend: {
directory: './frontend',
cmd: 'npm',
args: ['run', 'build'],
},
go_build_w: {
directory: './go',
cmd: 'go',
args: ['build', '-o', '../build/extraResources/goapp.exe'],
},
go_build_m: {
directory: './go',
cmd: 'go',
args: ['build', '-o', '../build/extraResources/goapp'],
},
go_build_l: {
directory: './go',
cmd: 'go',
args: ['build', '-o', '../build/extraResources/goapp'],
}
},
/**
* 前端构建
* ee-bin build
*/
build: {
directory: './frontend',
cmd: 'npm',
args: ['run', 'build'],
},
/**
* 移动资源
* ee-bin rd
* ee-bin move
*/
rd: {
dist: './frontend/dist',
target: './public/dist'
},
move: {
frontend_dist: {
dist: './frontend/dist',
target: './public/dist'
},
go_static: {
dist: './frontend/dist',
target: './go/public/dist'
},
go_config: {
dist: './go/config',
target: './go/public/config'
},
go_package: {
dist: './package.json',
target: './go/public/package.json'
},
go_images: {
dist: './public/images',
target: './go/public/images'
}
},
/**
* 预发布模式prod
@@ -79,25 +119,20 @@ module.exports = {
* ee-bin exec
*/
exec: {
go_dev: {
go_test: {
directory: './go',
cmd: 'go',
args: ['run', './main.go', '--env=dev'],
args: ['run', './main.go', '--env=prod','--basedir=../', '--port=7073', '--debug=true'],
},
go_build_w: {
directory: './go',
cmd: 'go',
args: ['build', '-o', '../build/extraResources/core.exe'],
node_v: {
directory: './',
cmd: 'node',
args: ['-v'],
},
go_build_m: {
directory: './go',
cmd: 'go',
args: ['build', '-o core', '--env=prod'],
npm_v: {
directory: './',
cmd: 'npm',
args: ['-v'],
},
go_build_l: {
directory: './go',
cmd: 'go',
args: ['build', '-o core', '--env=prod'],
}
},
};

View File

@@ -29,7 +29,7 @@ module.exports = (appInfo) => {
minWidth: 400,
minHeight: 300,
webPreferences: {
webSecurity: false,
//webSecurity: false,
contextIsolation: false, // false -> 可在渲染进程中使用electron的apitrue->需要bridge.js(contextBridge)
nodeIntegration: true,
//preload: path.join(appInfo.baseDir, 'preload', 'bridge.js'),
@@ -116,8 +116,23 @@ module.exports = (appInfo) => {
indexPath: '/public/dist/index.html',
host: '127.0.0.1',
port: 7072,
loadingPage: '/public/html/loading.html',
takeover: 'go'
};
/**
* Cross-language service
* 跨语言服务
* 例如执行go的二进制程序
*/
config.cross = {
go: {
enable: false,
name: 'goapp',
args: ['--env=dev', '--port=7073'],
}
};
/**
* 硬件加速
*/

36
go/api/example.go Normal file
View File

@@ -0,0 +1,36 @@
package api
import (
"net/http"
"github.com/wallace5303/ee-go/eapp"
"github.com/wallace5303/ee-go/ehelper"
"github.com/wallace5303/ee-go/ehttp/router"
"github.com/wallace5303/ee-go/elog"
"github.com/gin-gonic/gin"
)
// 使用 router Ctx
func Hello(c *router.Ctx) {
ret := ehelper.GetJson()
defer c.JSON(ret)
ret.Data = "hello electron-egg"
elog.Logger.Info(" print Hello ")
}
// 使用 gin Context
func Info(gc *gin.Context) {
ret := ehelper.GetJson()
defer gc.JSON(http.StatusOK, ret)
elog.Logger.Info(" print info ")
}
func Exit(c *router.Ctx) {
ret := ehelper.GetJson()
defer c.JSON(ret)
eapp.Close()
}

View File

@@ -1,22 +0,0 @@
package api
import (
"net/http"
"ee-go/eruntime"
"ee-go/eserver"
"github.com/gin-gonic/gin"
)
func GetName(ctx *gin.Context) {
ret := eserver.NewJson()
defer ctx.JSON(http.StatusOK, ret)
}
func Exit(ctx *gin.Context) {
ret := eserver.NewJson()
defer ctx.JSON(http.StatusOK, ret)
eruntime.Close()
}

View File

@@ -6,12 +6,27 @@
"max_size": 1024,
"max_age": 10
},
"http": {
"core_logger": {
"output_json": false,
"level": "info",
"filename": "ee-go-core.log",
"max_size": 1024,
"max_age": 10
},
"http": {
"enable": true,
"protocol": "http://",
"hostname": "127.0.0.1",
"port": 7073,
"indexPath": "",
"index_path": "",
"network": false
},
"static": {
"enable": true,
"package": "public/package.json",
"config": "public/config",
"dist": "public/dist",
"html": "public/html",
"ssl": "public/ssl"
}
}

View File

@@ -6,7 +6,7 @@
"max_size": 1024,
"max_age": 20
},
"http": {
"http": {
"enable": true,
"protocol": "http://",
"hostname": "127.0.0.1",

View File

@@ -6,7 +6,14 @@
"max_size": 1024,
"max_age": 30
},
"http": {
"core_logger": {
"output_json": true,
"level": "info",
"filename": "ee-go-core.log",
"max_size": 1024,
"max_age": 10
},
"http": {
"enable": true,
"protocol": "http://",
"hostname": "127.0.0.1",

View File

@@ -2,11 +2,8 @@ module electron-egg
go 1.20
//ee-go v1.0.0
require github.com/gin-gonic/gin v1.9.1
// replace ee-go => D:\www\bilibili\gofile\src\ee-core\ee-go
require (
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect

View File

@@ -1,18 +1,25 @@
package main
import (
"ee-go/eboot"
"embed"
"github.com/wallace5303/ee-go/eboot"
"electron-egg/router"
)
var (
//go:embed public/**
staticFS embed.FS
)
func main() {
// Initialize ee-go
eboot.Init()
ego := eboot.New(staticFS)
// User business logic
router.Load()
router.Api()
// ee-go runtime
eboot.Run()
ego.Run()
}

5
go/public/read.txt Normal file
View File

@@ -0,0 +1,5 @@
该目录存放静态资源
move 命令会将 electron-egg/public 资源,移动到这里;
go程序构建时会将该资源嵌入到 二进制文件中。

View File

@@ -3,10 +3,15 @@ package router
import (
"electron-egg/api"
"ee-go/eserver"
eRouter "github.com/wallace5303/ee-go/ehttp/router"
)
func Load() {
eserver.Router.Handle("GET", "/api/user/getName", api.GetName)
eserver.Router.Handle("GET", "/api/user/exit", api.Exit)
func Api() {
// 注册路由
eRouter.Handle("GET", "/api/hello", api.Hello)
eRouter.Handle("GET", "/api/exit", api.Exit)
// 使用 gin 注册路由
eRouter.GinRouter.GET("/api/info", api.Info)
}

View File

@@ -7,13 +7,14 @@
"dev": "ee-bin dev",
"dev-frontend": "ee-bin dev --serve=frontend",
"dev-electron": "ee-bin dev --serve=electron",
"dev-go": "ee-bin exec --command=go_dev",
"build-frontend": "ee-bin build",
"build-go-w": "ee-bin exec --command=go_build_w",
"build-go-m": "ee-bin exec --command=go_build_m",
"build-go-l": "ee-bin exec --command=go_build_l",
"dev-go": "ee-bin dev --serve=go",
"build-frontend": "ee-bin build --cmds=frontend",
"build-go-w": "ee-bin build --cmds=go_build_w",
"build-go-m": "ee-bin build --cmds=go_build_m",
"build-go-l": "ee-bin build --cmds=go_build_l",
"start": "ee-bin start",
"rd": "ee-bin rd",
"move": "ee-bin move --flag=go_static,go_config,go_package,go_images",
"rd": "ee-bin move --flag=frontend_dist",
"encrypt": "ee-bin encrypt",
"clean": "ee-bin clean",
"icon": "ee-bin icon",

94
public/html/loading.html Normal file
View File

@@ -0,0 +1,94 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1.0, minimum-scale=1.0" />
<style>
#loadingPage {
background-color: #dedede;
font-size: 12px;
}
.base {
left: 50%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
}
.desc {
margin: 0, 0, 20px, 0;
}
.loading,
.loading > div {
position: relative;
box-sizing: border-box;
}
.loading {
display: block;
font-size: 0;
color: #06b359;
}
.loading.la-dark {
color: #07C160;
}
.loading > div {
display: inline-block;
float: none;
background-color: currentColor;
border: 0 solid currentColor;
}
.loading {
width: 92px;
height: 92px;
}
.loading > div {
position: absolute;
top: 50%;
left: 50%;
background: transparent;
border-style: solid;
border-width: 2px;
border-radius: 100%;
animation: ball-clip-rotate-multiple-rotate 1s ease-in-out infinite;
}
.loading > div:first-child {
position: absolute;
width: 92px;
height: 92px;
border-right-color: transparent;
border-left-color: transparent;
}
.loading > div:last-child {
width: 16px;
height: 16px;
border-top-color: transparent;
border-bottom-color: transparent;
animation-duration: 0.5s;
animation-direction: reverse;
}
@keyframes ball-clip-rotate-multiple-rotate {
0% {
transform: translate(-50%, -50%) rotate(0deg);
}
50% {
transform: translate(-50%, -50%) rotate(180deg);
}
100% {
transform: translate(-50%, -50%) rotate(360deg);
}
}
</style>
</head>
<body>
<div id="boot">
<div class='base'>
<div class="loading">
<div></div>
<div></div>
</div>
</div>
</div>
</body>
</html>