diff --git a/.gitignore b/.gitignore index d17f435..485537b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ public/electron/ pnpm-lock.yaml .yalc/ yalc.lock +go/public/ +build/extraResources/core.exe +build/extraResources/goapp.exe diff --git a/electron/config/bin.js b/electron/config/bin.js index a9e818a..8ce4eed 100644 --- a/electron/config/bin.js +++ b/electron/config/bin.js @@ -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'], - } }, }; \ No newline at end of file diff --git a/electron/config/config.default.js b/electron/config/config.default.js index be57281..e37c73f 100644 --- a/electron/config/config.default.js +++ b/electron/config/config.default.js @@ -29,7 +29,7 @@ module.exports = (appInfo) => { minWidth: 400, minHeight: 300, webPreferences: { - webSecurity: false, + //webSecurity: false, contextIsolation: false, // false -> 可在渲染进程中使用electron的api,true->需要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'], + } + }; + /** * 硬件加速 */ diff --git a/go/api/example.go b/go/api/example.go new file mode 100644 index 0000000..9aa8f21 --- /dev/null +++ b/go/api/example.go @@ -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() +} diff --git a/go/api/user.go b/go/api/user.go deleted file mode 100644 index de0acc9..0000000 --- a/go/api/user.go +++ /dev/null @@ -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() -} diff --git a/go/config/config.default.json b/go/config/config.default.json index 09039a2..a4b09d9 100644 --- a/go/config/config.default.json +++ b/go/config/config.default.json @@ -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" } } \ No newline at end of file diff --git a/go/config/config.local.json b/go/config/config.local.json index 1cdd5e9..c01d9b2 100644 --- a/go/config/config.local.json +++ b/go/config/config.local.json @@ -6,7 +6,7 @@ "max_size": 1024, "max_age": 20 }, - "http": { + "http": { "enable": true, "protocol": "http://", "hostname": "127.0.0.1", diff --git a/go/config/config.prod.json b/go/config/config.prod.json index 8ed26b2..9481ddb 100644 --- a/go/config/config.prod.json +++ b/go/config/config.prod.json @@ -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", diff --git a/go/go.mod b/go/go.mod index e9b0560..d681351 100644 --- a/go/go.mod +++ b/go/go.mod @@ -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 diff --git a/go/main.go b/go/main.go index 2ef9117..8f5bec9 100644 --- a/go/main.go +++ b/go/main.go @@ -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() } diff --git a/go/public/read.txt b/go/public/read.txt new file mode 100644 index 0000000..d2f070e --- /dev/null +++ b/go/public/read.txt @@ -0,0 +1,5 @@ +该目录存放静态资源 + +move 命令会将 electron-egg/public 资源,移动到这里; + +go程序构建时,会将该资源嵌入到 二进制文件中。 \ No newline at end of file diff --git a/go/router/router.go b/go/router/router.go index 3892737..c3e38f5 100644 --- a/go/router/router.go +++ b/go/router/router.go @@ -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) } diff --git a/package.json b/package.json index 956190d..a8a9fa9 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/public/html/loading.html b/public/html/loading.html new file mode 100644 index 0000000..9d1520b --- /dev/null +++ b/public/html/loading.html @@ -0,0 +1,94 @@ + + + + + + + + + +
+
+
+
+
+
+
+
+ +