How to add a GUI to your Golang app in 5 easy steps (powered by Electron)

Step 1: organize the project

|--+ resources
|--+ app
|--+ static
|--+ css
|--+ base.css
|--+ js
|--+ index.js
|--+ lib
|--+ ... (all the css/js libs we need)
|--+ index.html
|--+ icon.icns
|--+ icon.ico
|--+ icon.png
|--+ bundler.json
|--+ main.go
|--+ message.go

Step 2: implement the skeleton

GO

HTML

CSS

JS

Step 3: set up the communication between GO and Javascript

Communicating from Javascript to GO

Communicating from GO to Javascript

Step 4: bundle the app

  • a MacOSX app for darwin users
  • an .exe with a nice icon for windows users
  • a simple binary for linux users
$ go get -u github.com/asticode/go-astilectron-bundler/...
$ astilectron-bundler -v

Step 5: see it in action!

Conclusion

  • the size of the binary will be at least 50MB, and after the first execution the size of the folder containing the binary will be at least 200MB
  • the memory consumption can be a little bit hectic since Electron (that is running under the hood) has been known to not manage it that well

Freelance | Senior Backend Developer (GO) | https://asticode.com | https://github.com/asticode

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How fast is your code?

Linting is parenting

Creating a Step Sequencer with Tone.js

Frontend Weekly Digest #162 (8 –14 June 2020)

Pro tips using localStorage

What is Queue in Data Structure?

React?? Who are you!!

Adding Multiple Conditions to Numpy

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Quentin Renard

Quentin Renard

Freelance | Senior Backend Developer (GO) | https://asticode.com | https://github.com/asticode

More from Medium

Delve With VSCode To Debug Go App

Build a REST API with Golang and MongoDB — Fiber Version

Getting started with GO Programming Language — Part Two

Five Minutes to Start Learning Unit Test in Golang