Import Alias
// `rt` is an alias of "github.com/wailsapp/wails/v2/pkg/runtime" to prevent collision with standard package
The comment is referring to an import alias. An import alias is a local renaming of the imported package to be used in the file. See also the question How to import and use different packages of the same name.
In this case, the comment means that instead of using the name runtime, they have aliased it to rt. For example:
import ( rt "github.com/wailsapp/wails/v2/pkg/runtime" // aliased as `rt` )
This is necessary because the example code you are following also uses the standard library's runtime package, and so has to differentiate the two runtime packages to avoid a naming collision. For instance:
import ( "runtime" // `runtime` rt "github.com/wailsapp/wails/v2/pkg/runtime" // aliased as `rt` )
Now you can use both packages together in the same file without a compilation error.
Complete Example
We can add imports to the menu example for a complete, runnable example as such:
menu.go:
package main import ( "log" "runtime" "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/menu" "github.com/wailsapp/wails/v2/pkg/menu/keys" "github.com/wailsapp/wails/v2/pkg/options" rt "github.com/wailsapp/wails/v2/pkg/runtime" ) func main() { // Sourced largely from (with some fixes): https://github.com/wailsapp/wails/blob/4c464b3092fff35b993f31ca62ca612399dde970/website/docs/reference/menus.mdx?plain=1#L13 app := NewApp() AppMenu := menu.NewMenu() if runtime.GOOS == "darwin" { AppMenu.Append(menu.AppMenu()) // On macOS platform, this must be done right after `NewMenu()` } FileMenu := AppMenu.AddSubmenu("File") FileMenu.AddText("&Open", keys.CmdOrCtrl("o"), func(_ *menu.CallbackData) { // do something }) FileMenu.AddSeparator() FileMenu.AddText("Quit", keys.CmdOrCtrl("q"), func(_ *menu.CallbackData) { // `rt` is an alias of "github.com/wailsapp/wails/v2/pkg/runtime" to prevent collision with standard package rt.Quit(app.ctx) }) if runtime.GOOS == "darwin" { AppMenu.Append(menu.EditMenu()) // On macOS platform, EditMenu should be appended to enable Cmd+C, Cmd+V, Cmd+Z... shortcuts } err := wails.Run(&options.App{ Title: "Menus Demo", Width: 800, Height: 600, Menu: AppMenu, // reference the menu above Bind: []interface{}{ app, }, }) // ... if err != nil { log.Fatal(err) } }
To get this to fully run, we also need to include the NewApp() / app.go scaffold in another file:
app.go (source example):
package main import ( "context" "fmt" ) // App struct type App struct { ctx context.Context } // NewApp creates a new App application struct func NewApp() *App { return &App{} } // startup is called when the app starts. The context is saved // so we can call the runtime methods func (a *App) startup(ctx context.Context) { a.ctx = ctx } // Greet returns a greeting for the given name func (a *App) Greet(name string) string { return fmt.Sprintf("Hello %s, It's show time!", name) }
With these two files fully defined, you can now compile this on the Go Playground. Note that it eventually errors out as it can't be fully run in that environment.