electron-egg electron-egg
首页
  • v4.x
  • v3.x
  • v2.x
插件
  • v4.x
  • v3.x
demo
支持
知识点
案例
交流
  • GitHub (opens new window)
  • Gitee (opens new window)
首页
  • v4.x
  • v3.x
  • v2.x
插件
  • v4.x
  • v3.x
demo
支持
知识点
案例
交流
  • GitHub (opens new window)
  • Gitee (opens new window)
❤️成为赞助商
  • 快速入门

  • 基础功能

  • 生成软件

  • 升级

  • 跨语言支持

    • 介绍
    • go

      • 开始
        • 配置
        • 开发
        • 构建
        • 日志
        • 数据
        • main.go
        • 路由
        • 业务层
        • API
      • java

      • python

    • 更新记录
    • 常见问题
    目录

    开始

    ee-bin: v1.6.0

    ee-core: v2.10.1

    go 1.20.4

    go 凭借着简单、高效、跨平台等优势,迅速成为开发者最喜爱的语言之一。

    electron-egg 深度集成了go,并通过 ee-go mod,让开发者非常方便的进程业务开发,而无需关注复杂的系统环境。

    如果您将核心业务用go来开发,那么它将拥有堪比c#、qt一样流畅的使用体验。

    注:为了简化开发,请升级ee-core >= 2.10.2

    # 准备

    • 推荐 go 1.20.4
    • 注:go 1.20 是支持win7、macOS 10.x 的最后一个版本

    # 下载安装

    1. 下载项目
    # gitee
    git clone https://gitee.com/dromara/electron-egg.git
    
    # github
    git clone https://github.com/dromara/electron-egg.git
    
    1. 切换 demo 分支
    git checkout -b demo-go remotes/origin/demo
    
    1. 安装 前端、electron、go 依赖
    # 根目录安装electron依赖
    npm i
    
    # 进入前端目录安装依赖
    cd ./frontend 
    npm i
    
    # 先全局安装热重载 air
    go install github.com/air-verse/air@v1.49.0
    # 进入go目录安装依赖
    cd ../go
    go mod tidy
    

    # 在electron中如何运行go的可执行程序

    提供两种启动方式。1:通过配置启动;2:通过cross模块的API来启动。

    # 方式一:配置模式

    请查看文档:配置

    执行命令npm run dev-electron时,会自动拉起go项目/程序。

    # 方式二:API模式

    创建go服务

    // 文件 electron/service/cross.js
    
    async createGoServer() {
      // method 1: Use the default Settings
      //const entity = await Cross.run(serviceName);
    
      // method 2: Use custom configuration
      const serviceName = "go";
      const opt = {
        // 程序名称,一般填写可执行程序名
        name: 'goapp',
        cmd: path.join(Ps.getExtraResourcesDir(), 'goapp'),
        directory: Ps.getExtraResourcesDir(),
        args: ['--port=7073'],
        // 程序退出时,是否退出electron应用
        appExit: true,
      }
      const entity = await Cross.run(serviceName, opt);
      Log.info('server name:', entity.name);
    
      return;
    }
    

    # 跟随软件启动

    如果你希望桌面软件运行时就启动go服务,有以下两种方式。

    一:通过config.default.js中的配置:查看

    二:在预加载模块,直接引入Services并调用。

    // 文件 electron/preload/index.js
    
    /*************************************************
     ** preload为预加载模块,该文件将会在程序启动时加载 **
     *************************************************/
    const Addon = require('ee-core/addon');
    const Services = require('ee-core/services');
    
    /**
     * 预加载模块入口
     */
    module.exports = async () => {
    
      // 直接调用
      Services.get('cross').createGoServer();
    }
    
    上次更新: 2025/06/06, 07:21:49
    介绍
    配置

    ← 介绍 配置→

    Theme by Vdoing | Copyright © 2023-2025 哆啦好梦 | 京ICP备15041380号-2
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式
    ×