DEV Community

Alex Spinov
Alex Spinov

Posted on

Wails Has a Free API You've Never Heard Of

Wails lets you build desktop applications using Go and web technologies. Unlike Electron, it uses the native webview and produces tiny binaries. Think Tauri, but for Go developers.

What Makes Wails Special?

  • Go backend — full power of Go's ecosystem
  • Native webview — no bundled Chromium
  • Tiny binaries — 5-10MB vs Electron's 150MB+
  • Auto-binding — Go functions auto-exposed to JavaScript
  • Cross-platform — Windows, macOS, Linux

The Hidden API: Go-JavaScript Bridge

package main

import (
    "context"
    "fmt"
)

type App struct {
    ctx context.Context
}

// Automatically exposed to JavaScript!
func (a *App) Greet(name string) string {
    return fmt.Sprintf("Hello %s!", name)
}

func (a *App) ReadFile(path string) (string, error) {
    data, err := os.ReadFile(path)
    return string(data), err
}

func (a *App) QueryDatabase(sql string) ([]map[string]interface{}, error) {
    rows, err := db.Query(sql)
    // ... process rows
    return results, err
}
Enter fullscreen mode Exit fullscreen mode
// Frontend — call Go functions with full TypeScript types
import { Greet, ReadFile, QueryDatabase } from '../wailsjs/go/main/App';

const greeting = await Greet('World'); // "Hello World!"
const content = await ReadFile('/etc/hosts');
const users = await QueryDatabase('SELECT * FROM users');
Enter fullscreen mode Exit fullscreen mode

Events API — Bidirectional Communication

// Go → JavaScript events
runtime.EventsEmit(a.ctx, "file-changed", filename);
runtime.EventsEmit(a.ctx, "download-progress", progress);

// Listen for JavaScript → Go events
runtime.EventsOn(a.ctx, "user-action", func(data ...interface{}) {
    fmt.Println("User did:", data[0])
})
Enter fullscreen mode Exit fullscreen mode
// JavaScript side
import { EventsOn, EventsEmit } from '../wailsjs/runtime';

EventsOn('file-changed', (filename: string) => {
  console.log('File changed:', filename);
});

EventsEmit('user-action', 'clicked-save');
Enter fullscreen mode Exit fullscreen mode

System Dialogs API

func (a *App) SelectFile() (string, error) {
    return runtime.OpenFileDialog(a.ctx, runtime.OpenDialogOptions{
        Title: "Select a file",
        Filters: []runtime.FileFilter{
            {DisplayName: "Images", Pattern: "*.png;*.jpg;*.jpeg"},
        },
    })
}
Enter fullscreen mode Exit fullscreen mode

Quick Start

go install github.com/wailsapp/wails/v2/cmd/wails@latest
wails init -n myapp -t react-ts
cd myapp && wails dev
Enter fullscreen mode Exit fullscreen mode

Why Go Developers Choose Wails

A Go developer shared: "I wanted to build a desktop tool for our team. Electron felt wrong for a Go shop. Wails let me keep our entire backend in Go while the frontend team used React. The binary is 8MB and starts in 200ms."


Building desktop apps with Go? Email spinov001@gmail.com or check my tools.

Go for desktop apps — Wails vs Fyne vs Gio? What's your choice?

Top comments (0)