From 77c2a06277b84028d19ba1be386fad9b8f82213f Mon Sep 17 00:00:00 2001 From: Muhammad Asim Date: Thu, 12 Mar 2026 15:59:55 +0500 Subject: [PATCH 1/3] type mis-match corrected and add connection cleanup there was a type mis-match for AllBreeds struct. the url return map[string][]string which causes application to mis-behave. also added connection close to the http request and some minor imporovements. --- website/docs/tutorials/dogsapi.mdx | 48 ++++++++++--------- .../version-v2.11.0/tutorials/dogsapi.mdx | 48 ++++++++++--------- 2 files changed, 52 insertions(+), 44 deletions(-) diff --git a/website/docs/tutorials/dogsapi.mdx b/website/docs/tutorials/dogsapi.mdx index 011ebe266..915b558e9 100644 --- a/website/docs/tutorials/dogsapi.mdx +++ b/website/docs/tutorials/dogsapi.mdx @@ -64,7 +64,7 @@ type RandomImage struct { } type AllBreeds struct { - Message map[string]map[string][]string + Message map[string][]string Status string } @@ -77,16 +77,20 @@ type ImagesByBreed struct { Add the following functions to `app.go` (perhaps after the existing function definitions): ```go +// INFO: application error handling +func handleError(err error) { + if err != nil { + log.Fatal(err) + } +} + func (a *App) GetRandomImageUrl() string { response, err := http.Get("https://dog.ceo/api/breeds/image/random") - if err != nil { - log.Fatal(err) - } + handleError(err) + defer response.Body.Close() responseData, err := ioutil.ReadAll(response.Body) - if err != nil { - log.Fatal(err) - } + handleError(err) var data RandomImage json.Unmarshal(responseData, &data) @@ -98,14 +102,11 @@ func (a *App) GetBreedList() []string { var breeds []string response, err := http.Get("https://dog.ceo/api/breeds/list/all") - if err != nil { - log.Fatal(err) - } + handleError(err) + defer response.Body.Close() responseData, err := ioutil.ReadAll(response.Body) - if err != nil { - log.Fatal(err) - } + handleError(err) var data AllBreeds json.Unmarshal(responseData, &data) @@ -123,14 +124,11 @@ func (a *App) GetImageUrlsByBreed(breed string) []string { url := fmt.Sprintf("%s%s%s%s", "https://dog.ceo/api/", "breed/", breed, "/images") response, err := http.Get(url) - if err != nil { - log.Fatal(err) - } + handleError(err) + defer response.Body.Close() responseData, err := ioutil.ReadAll(response.Body) - if err != nil { - log.Fatal(err) - } + handleError(err) var data ImagesByBreed json.Unmarshal(responseData, &data) @@ -170,7 +168,7 @@ Add the following lines to `frontend/src/App.svelte`: let showBreedPhotos = false; function init() { - getBreedList(); + getBreedList().then(result => breeds = result); } init(); @@ -178,8 +176,11 @@ Add the following lines to `frontend/src/App.svelte`: function getRandomImageUrl() { showRandomPhoto = false; showBreedPhotos = false; - GetRandomImageUrl().then((result) => (randomImageUrl = result)); + + GetRandomImageUrl().then((result) => { + randomImageUrl = result showRandomPhoto = true; + }); } function getBreedList() { @@ -190,8 +191,11 @@ Add the following lines to `frontend/src/App.svelte`: init(); showRandomPhoto = false; showBreedPhotos = false; - GetImageUrlsByBreed(selectedBreed).then((result) => (photos = result)); + + GetImageUrlsByBreed(selectedBreed).then((result) => { + photos = result showBreedPhotos = true; + }); } diff --git a/website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx b/website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx index 011ebe266..915b558e9 100644 --- a/website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx +++ b/website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx @@ -64,7 +64,7 @@ type RandomImage struct { } type AllBreeds struct { - Message map[string]map[string][]string + Message map[string][]string Status string } @@ -77,16 +77,20 @@ type ImagesByBreed struct { Add the following functions to `app.go` (perhaps after the existing function definitions): ```go +// INFO: application error handling +func handleError(err error) { + if err != nil { + log.Fatal(err) + } +} + func (a *App) GetRandomImageUrl() string { response, err := http.Get("https://dog.ceo/api/breeds/image/random") - if err != nil { - log.Fatal(err) - } + handleError(err) + defer response.Body.Close() responseData, err := ioutil.ReadAll(response.Body) - if err != nil { - log.Fatal(err) - } + handleError(err) var data RandomImage json.Unmarshal(responseData, &data) @@ -98,14 +102,11 @@ func (a *App) GetBreedList() []string { var breeds []string response, err := http.Get("https://dog.ceo/api/breeds/list/all") - if err != nil { - log.Fatal(err) - } + handleError(err) + defer response.Body.Close() responseData, err := ioutil.ReadAll(response.Body) - if err != nil { - log.Fatal(err) - } + handleError(err) var data AllBreeds json.Unmarshal(responseData, &data) @@ -123,14 +124,11 @@ func (a *App) GetImageUrlsByBreed(breed string) []string { url := fmt.Sprintf("%s%s%s%s", "https://dog.ceo/api/", "breed/", breed, "/images") response, err := http.Get(url) - if err != nil { - log.Fatal(err) - } + handleError(err) + defer response.Body.Close() responseData, err := ioutil.ReadAll(response.Body) - if err != nil { - log.Fatal(err) - } + handleError(err) var data ImagesByBreed json.Unmarshal(responseData, &data) @@ -170,7 +168,7 @@ Add the following lines to `frontend/src/App.svelte`: let showBreedPhotos = false; function init() { - getBreedList(); + getBreedList().then(result => breeds = result); } init(); @@ -178,8 +176,11 @@ Add the following lines to `frontend/src/App.svelte`: function getRandomImageUrl() { showRandomPhoto = false; showBreedPhotos = false; - GetRandomImageUrl().then((result) => (randomImageUrl = result)); + + GetRandomImageUrl().then((result) => { + randomImageUrl = result showRandomPhoto = true; + }); } function getBreedList() { @@ -190,8 +191,11 @@ Add the following lines to `frontend/src/App.svelte`: init(); showRandomPhoto = false; showBreedPhotos = false; - GetImageUrlsByBreed(selectedBreed).then((result) => (photos = result)); + + GetImageUrlsByBreed(selectedBreed).then((result) => { + photos = result showBreedPhotos = true; + }); } From 5d5f06f1052423055f8c1a6c8041a4f818fff392 Mon Sep 17 00:00:00 2001 From: Muhammad Asim Date: Thu, 12 Mar 2026 16:36:08 +0500 Subject: [PATCH 2/3] GetBreedList() didnt return promise the GetBreedList do not return promise and populates the files internally --- website/docs/tutorials/dogsapi.mdx | 6 +++--- .../versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/website/docs/tutorials/dogsapi.mdx b/website/docs/tutorials/dogsapi.mdx index 915b558e9..283761a04 100644 --- a/website/docs/tutorials/dogsapi.mdx +++ b/website/docs/tutorials/dogsapi.mdx @@ -178,13 +178,13 @@ Add the following lines to `frontend/src/App.svelte`: showBreedPhotos = false; GetRandomImageUrl().then((result) => { - randomImageUrl = result + randomImageUrl = result; showRandomPhoto = true; }); } function getBreedList() { - GetBreedList().then((result) => (breeds = result)); + GetBreedList(); } function getImageUrlsByBreed() { @@ -193,7 +193,7 @@ Add the following lines to `frontend/src/App.svelte`: showBreedPhotos = false; GetImageUrlsByBreed(selectedBreed).then((result) => { - photos = result + photos = result; showBreedPhotos = true; }); } diff --git a/website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx b/website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx index 915b558e9..2804b80c3 100644 --- a/website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx +++ b/website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx @@ -184,7 +184,7 @@ Add the following lines to `frontend/src/App.svelte`: } function getBreedList() { - GetBreedList().then((result) => (breeds = result)); + GetBreedList(); } function getImageUrlsByBreed() { @@ -193,7 +193,7 @@ Add the following lines to `frontend/src/App.svelte`: showBreedPhotos = false; GetImageUrlsByBreed(selectedBreed).then((result) => { - photos = result + photos = result; showBreedPhotos = true; }); } From 4b31f543b32a6ed854672860190bdf29d82f44f2 Mon Sep 17 00:00:00 2001 From: Muhammad Asim Date: Thu, 12 Mar 2026 23:26:02 +0500 Subject: [PATCH 3/3] suggestions from code rabbit about promise --- website/docs/tutorials/dogsapi.mdx | 26 +++++++++-------- .../version-v2.11.0/tutorials/dogsapi.mdx | 28 +++++++++++-------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/website/docs/tutorials/dogsapi.mdx b/website/docs/tutorials/dogsapi.mdx index 283761a04..68fb3c996 100644 --- a/website/docs/tutorials/dogsapi.mdx +++ b/website/docs/tutorials/dogsapi.mdx @@ -17,21 +17,22 @@ sidebar_position: 20 :::note -This tutorial has been kindly provided by [@tatadan](https://twitter.com/tatadan) and forms part of -their [Wails Examples Repository](https://github.com/tataDan/wails-v2-examples). +This tutorial has been kindly provided by +[@tatadan](https://twitter.com/tatadan) and forms part of their +[Wails Examples Repository](https://github.com/tataDan/wails-v2-examples). ::: -In this tutorial we are going to develop an application that retrieves photos of dogs from the web -and then displays them. +In this tutorial we are going to develop an application that retrieves photos of +dogs from the web and then displays them. ### Create the project Let's create the application. From a terminal enter: `wails init -n dogs-api -t svelte` -Note: We could optionally add `-ide vscode` or `-ide goland` to the end of this command if you wanted -to add IDE support. +Note: We could optionally add `-ide vscode` or `-ide goland` to the end of this +command if you wanted to add IDE support. Now let's `cd dogs-api` and start editing the project files. @@ -55,7 +56,8 @@ func (a *App) Greet(name string) string { Now let's add our new Go code. -Add the following struct declarations to `app.go` before the function definitions: +Add the following struct declarations to `app.go` before the function +definitions: ```go type RandomImage struct { @@ -74,7 +76,8 @@ type ImagesByBreed struct { } ``` -Add the following functions to `app.go` (perhaps after the existing function definitions): +Add the following functions to `app.go` (perhaps after the existing function +definitions): ```go // INFO: application error handling @@ -168,7 +171,7 @@ Add the following lines to `frontend/src/App.svelte`: let showBreedPhotos = false; function init() { - getBreedList().then(result => breeds = result); + getBreedList(); } init(); @@ -184,7 +187,7 @@ Add the following lines to `frontend/src/App.svelte`: } function getBreedList() { - GetBreedList(); + GetBreedList().then(result => breeds = result);; } function getImageUrlsByBreed() { @@ -250,4 +253,5 @@ To generate the bindings and test the application, run `wails dev`. ### Compiling the application -To compile the application to a single, production grade binary, run `wails build`. +To compile the application to a single, production grade binary, run +`wails build`. diff --git a/website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx b/website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx index 2804b80c3..68fb3c996 100644 --- a/website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx +++ b/website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx @@ -17,21 +17,22 @@ sidebar_position: 20 :::note -This tutorial has been kindly provided by [@tatadan](https://twitter.com/tatadan) and forms part of -their [Wails Examples Repository](https://github.com/tataDan/wails-v2-examples). +This tutorial has been kindly provided by +[@tatadan](https://twitter.com/tatadan) and forms part of their +[Wails Examples Repository](https://github.com/tataDan/wails-v2-examples). ::: -In this tutorial we are going to develop an application that retrieves photos of dogs from the web -and then displays them. +In this tutorial we are going to develop an application that retrieves photos of +dogs from the web and then displays them. ### Create the project Let's create the application. From a terminal enter: `wails init -n dogs-api -t svelte` -Note: We could optionally add `-ide vscode` or `-ide goland` to the end of this command if you wanted -to add IDE support. +Note: We could optionally add `-ide vscode` or `-ide goland` to the end of this +command if you wanted to add IDE support. Now let's `cd dogs-api` and start editing the project files. @@ -55,7 +56,8 @@ func (a *App) Greet(name string) string { Now let's add our new Go code. -Add the following struct declarations to `app.go` before the function definitions: +Add the following struct declarations to `app.go` before the function +definitions: ```go type RandomImage struct { @@ -74,7 +76,8 @@ type ImagesByBreed struct { } ``` -Add the following functions to `app.go` (perhaps after the existing function definitions): +Add the following functions to `app.go` (perhaps after the existing function +definitions): ```go // INFO: application error handling @@ -168,7 +171,7 @@ Add the following lines to `frontend/src/App.svelte`: let showBreedPhotos = false; function init() { - getBreedList().then(result => breeds = result); + getBreedList(); } init(); @@ -178,13 +181,13 @@ Add the following lines to `frontend/src/App.svelte`: showBreedPhotos = false; GetRandomImageUrl().then((result) => { - randomImageUrl = result + randomImageUrl = result; showRandomPhoto = true; }); } function getBreedList() { - GetBreedList(); + GetBreedList().then(result => breeds = result);; } function getImageUrlsByBreed() { @@ -250,4 +253,5 @@ To generate the bindings and test the application, run `wails dev`. ### Compiling the application -To compile the application to a single, production grade binary, run `wails build`. +To compile the application to a single, production grade binary, run +`wails build`.