Desktop Application Development with Go

The first curious topic when learning a new programming language, frameworks and what can be done about this technology.

Go programming language didn’t publish a desktop application framework as official. Because it is not its goal… The goal of Go is to develop system and Web server-focused infrastructure applications.

How is it?

I’ve seen many different ways to do desktop programming with Go. We can build desktop application using Electron.js, HTML-JS etc… But we want to use native solutions. That’s why, we’ll focus on the native Go frameworks.

What can we use?

My suggestion would be to use the Go framework created to work with Qt/QML. Qt is a very advanced and widely used framework. I’ll use the ‘ andlabs/ui ‘ framework as an example of this article. Actually, I’ll just do copy/paste from GitHub

Let’s start with example:

First, download the library ‘ andlabs/ui ‘:

go get github.com/andlabs/ui

Source code of the application:

package main
 
import (
    "github.com/andlabs/ui"
)
 
func main() {
    err := ui.Main(func() {
        name := ui.NewEntry()
        button := ui.NewButton("Selamla")
        greeting := ui.NewLabel("")
        box := ui.NewVerticalBox()
        box.Append(ui.NewLabel("Ad:"), false)
        box.Append(name, false)
        box.Append(button, false)
        box.Append(greeting, false)
        window := ui.NewWindow("Merhaba", 250, 100, false)
        window.SetChild(box)
        button.OnClicked(func(*ui.Button) {
            greeting.SetText("Merhaba, " + name.Text() + "!")
        })
        window.OnClosing(func(*ui.Window) bool {
            ui.Quit()
            return true
        })
        window.Show()
    })
    if err != nil {
        panic(err)
    }
}

When we run the project we’ll see the UI of the application. In the same way, we can work with ‘ go build ‘ simply by compiling the project We’ll be producing and .exe in this way. But it is not enough! Because this project will work with a console application in the background.

Therefore, we need to compile this application in the following way.

go build -ldflags -H=windowsgui main.go

Screenshots of the application

11

22

The source code of the above application you can access from the following link:

Original : http://www.cihanozhan.com/desktop-application-development-with-go/

1 Like

A web frontend project, a little like Gallium, that I like is Wails, https://wails.app/

https://github.com/fyne-io/fyne ?
https://github.com/go-flutter-desktop/go-flutter

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.