[v2] docs(app-dev): add imports to app.go examples (#4731)

* [v2] docs(app-dev): add imports to `app.go` examples

- add `context` and `fmt` imports to the `app.go` examples
- link to the docs for `context` when it is referenced for explicitness/beginner-friendliness

* add changelog entry per PR template

---------

Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
This commit is contained in:
Anton Gilgur 2025-11-30 01:21:27 -05:00 committed by GitHub
commit ef7d3301c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View file

@ -10,6 +10,10 @@ The pattern used by the default templates are that `main.go` is used for configu
The `app.go` file will define a struct that has 2 methods which act as hooks into the main application:
```go title="app.go"
import (
"context"
)
type App struct {
ctx context.Context
}
@ -28,7 +32,7 @@ func (a *App) shutdown(ctx context.Context) {
- The startup method is called as soon as Wails allocates the resources it needs and is a good place for creating resources,
setting up event listeners and anything else the application needs at startup.
It is given a `context.Context` which is usually saved in a struct field. This context is needed for calling the
It is given a [`context.Context`](https://pkg.go.dev/context) which is usually saved in a struct field. This context is needed for calling the
[runtime](../reference/runtime/intro.mdx). If this method returns an error, the application will terminate.
In dev mode, the error will be output to the console.
@ -65,7 +69,12 @@ More information on application lifecycle hooks can be found [here](../howdoesit
It is likely that you will want to call Go methods from the frontend. This is normally done by adding public methods to
the already defined struct in `app.go`:
```go {16-18} title="app.go"
```go {3,21-23} title="app.go"
import (
"context"
"fmt"
)
type App struct {
ctx context.Context
}

View file

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Updated Application Development guide to show imports in the `app.go` snippets by @agilgur5 in [#4731](https://github.com/wailsapp/wails/pull/4731)
- Fixed link to CoC in Community Guide when there was a trailing slash by @agilgur5 in [#4732](https://github.com/wailsapp/wails/pull/4732)
- Fixed indentation in "How does it work?" page by @agilgur5 in [#4733](https://github.com/wailsapp/wails/pull/4733)