Skip to content

Instantly share code, notes, and snippets.

@rafael-neri
Created December 19, 2025 14:38
Show Gist options
  • Select an option

  • Save rafael-neri/00d2b5a25f6d55e6e2bb360d1f38b33f to your computer and use it in GitHub Desktop.

Select an option

Save rafael-neri/00d2b5a25f6d55e6e2bb360d1f38b33f to your computer and use it in GitHub Desktop.
Webview using golang

Using Golang

Golang alternative using webview (modern, simple and lightweigth).

Install

go get github.com/webview/webview

Source Code

package main

import (
	"fmt"
	"net/url"
	"os"
	"path/filepath"

	"github.com/webview/webview"
)

type GoFileClass struct{}

func (g GoFileClass) SayHello(name string) {
	fmt.Println("Hello, ", name)
}

func main() {
	debug := false

	w := webview.New(debug)
	defer w.Destroy()

	// Window Title
	w.SetTitle("My Application")

	// Window Size
	w.SetSize(800, 600, webview.HintNone)

	// Path to HTML file
	cwd, _ := os.Getwd()
	htmlPath := filepath.Join(cwd, "index.html")
	u := url.URL{Scheme: "file", Path: htmlPath}

	// Bind Go ↔ JavaScript
	w.Bind("GoFileClass", GoFileClass{})

	// LoadHTML
	w.Navigate(u.String())

	// Execute
	w.Run()
}

Bind JS → Go

Add in you index.html:

<button onclick="GoFileClass.SayHello('World')">Say Hello</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment