Skip to content

go 1.20.4 ee-go 1.3.0

With its simplicity, efficiency, and cross-platform advantages, go has rapidly become one of the most popular languages among developers.

electron-egg deeply integrates Go, and through the ee-go mod, enables developers to conveniently perform business development without worrying about complex system environments.

If you develop your core business with Go, it will deliver a smooth user experience comparable to C# and Qt.

Preparation

  • Recommended: go 1.20.4
  • Note: go 1.20 is the last version that supports Windows 7 and macOS 10.x

Download and Install

  1. Download the project
bash
# gitee
git clone https://gitee.com/dromara/electron-egg.git

# github
git clone https://github.com/dromara/electron-egg.git
  1. Switch to the demo branch
bash
git checkout -b demo-go remotes/origin/demo
  1. Install frontend, Electron, and Go dependencies
bash
# Install Electron dependencies in the root directory
npm i

# Enter the frontend directory and install dependencies
cd ./frontend 
npm i

# First install the hot-reload tool air globally
go install github.com/air-verse/air@v1.49.0
# Enter the Go directory and install dependencies
cd ../go
go mod tidy

How to Run a Go Executable Program in Electron

Start it through the cross module API.

API Mode

Create a Go service

javascript
// File electron/service/cross.js
const { cross } = require('ee-core/cross');

async createGoServer() {
  // method 1: Use the default Settings
  //const entity = await cross.run(serviceName);

  // method 2: Use custom configuration
  const serviceName = "go";
  const opt = {
    // Program name, typically the executable name
    name: 'goapp',
    cmd: path.join(getExtraResourcesDir(), 'goapp'),
    directory: getExtraResourcesDir(),
    args: ['--port=7073'],
    // Whether to exit the Electron application when the program exits
    appExit: true,
  }
  const entity = await cross.run(serviceName, opt);
  logger.info('server name:', entity.name);

  return;
}

Start with Application Launch

If you want the Go service to start when the desktop application runs, there are several ways.

Method 1: Import and call directly in the preload module.

javascript
// File electron/preload/index.js

const { crossService } = require('../service/cross');

function preload() {
  // Call directly
  crossService.createGoServer();
}