Skip to content

Commit e3d5ed1

Browse files
committed
fix the playground
1 parent e33e732 commit e3d5ed1

File tree

10 files changed

+41
-70
lines changed

10 files changed

+41
-70
lines changed

playground/go/analytics.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56

67
"github.com/algolia/algoliasearch-client-go/v4/algolia/next/analytics"
78
)
89

9-
func testAnalytics(appID, apiKey string) int {
10+
func testAnalytics(ctx context.Context, appID, apiKey string) int {
1011
indexName := getEnvWithDefault("ANALYTICS_INDEX", "test_index")
1112
analyticsClient, err := analytics.NewClient(appID, apiKey, analytics.US)
1213
if err != nil {
1314
panic(err)
1415
}
1516

16-
getTopFilterForAttributeResponse, err := analyticsClient.GetTopFilterForAttribute("myAttribute1,myAttribute2", indexName, nil)
17+
getTopFilterForAttributeResponse, err := analyticsClient.GetTopFilterForAttribute(ctx, "myAttribute1,myAttribute2", indexName, nil)
1718
if err != nil {
1819
fmt.Printf("request error with GetTopFilterForAttribute: %v\n", err)
1920
return 1

playground/go/go.mod

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
11
module playground
22

3-
go 1.23.0
4-
5-
toolchain go1.24.1
3+
go 1.22
64

75
replace github.com/algolia/algoliasearch-client-go/v4 => ../../clients/algoliasearch-client-go
86

97
require (
108
github.com/algolia/algoliasearch-client-go/v4 v4.15.3
119
github.com/joho/godotenv v1.5.1
1210
)
13-
14-
require (
15-
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
16-
github.com/go-playground/locales v0.14.1 // indirect
17-
github.com/go-playground/universal-translator v0.18.1 // indirect
18-
github.com/go-playground/validator/v10 v10.26.0 // indirect
19-
github.com/leodido/go-urn v1.4.0 // indirect
20-
golang.org/x/crypto v0.36.0 // indirect
21-
golang.org/x/net v0.37.0 // indirect
22-
golang.org/x/sys v0.31.0 // indirect
23-
golang.org/x/text v0.23.0 // indirect
24-
)

playground/go/go.sum

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,2 @@
1-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
4-
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
5-
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
6-
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
7-
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
8-
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
9-
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
10-
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
11-
github.com/go-playground/validator/v10 v10.26.0 h1:SP05Nqhjcvz81uJaRfEV0YBSSSGMc/iMaVtFbr3Sw2k=
12-
github.com/go-playground/validator/v10 v10.26.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
131
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
142
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
15-
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
16-
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
17-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
18-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
19-
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
20-
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
21-
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
22-
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
23-
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
24-
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
25-
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
26-
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
27-
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
28-
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
29-
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
30-
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

playground/go/ingestion.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56

67
"github.com/algolia/algoliasearch-client-go/v4/algolia/next/ingestion"
78
)
89

9-
func testIngestion(appID, apiKey string) int {
10+
func testIngestion(ctx context.Context, appID, apiKey string) int {
1011
ingestionClient, err := ingestion.NewClient(appID, apiKey, ingestion.US)
1112
if err != nil {
1213
panic(err)
1314
}
1415

1516
// another example to generate payload for a request.
16-
res, err := ingestionClient.ListTasks(nil)
17+
res, err := ingestionClient.ListTasks(ctx, nil)
1718
if err != nil {
1819
fmt.Printf("request error: %v\n", err)
1920

playground/go/insights.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56

67
"github.com/algolia/algoliasearch-client-go/v4/algolia/next/insights"
78
)
89

9-
func testInsights(appID, apiKey string) int {
10+
func testInsights(ctx context.Context, appID, apiKey string) int {
1011
insightsClient, err := insights.NewClient(appID, apiKey, insights.US)
1112
if err != nil {
1213
panic(err)
@@ -20,7 +21,7 @@ func testInsights(appID, apiKey string) int {
2021
"myToken",
2122
insights.WithClickedObjectIDsTimestamp(1234567890))),
2223
}
23-
eventsResponse, err := insightsClient.PushEvents(events)
24+
eventsResponse, err := insightsClient.PushEvents(ctx, events)
2425
if err != nil {
2526
fmt.Printf("request error with PushEvents: %v\n", err)
2627
return 1

playground/go/main.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"flag"
56
"fmt"
67
"os"
@@ -10,7 +11,11 @@ import (
1011

1112
func main() {
1213
fmt.Println("Go playground")
13-
godotenv.Load("../.env")
14+
err := godotenv.Load("../.env")
15+
if err != nil {
16+
panic(fmt.Errorf("error loading .env file: %w", err))
17+
}
18+
1419
appID := os.Getenv("ALGOLIA_APPLICATION_ID")
1520
apiKey := os.Getenv("ALGOLIA_ADMIN_KEY")
1621

@@ -27,21 +32,23 @@ func main() {
2732

2833
// debug.Enable()
2934

35+
ctx := context.Background()
36+
3037
switch client {
3138
case "ingestion":
32-
returnCode = testIngestion(appID, apiKey)
39+
returnCode = testIngestion(ctx, appID, apiKey)
3340
case "search":
34-
returnCode = testSearch(appID, apiKey)
41+
returnCode = testSearch(ctx, appID, apiKey)
3542
case "analytics":
36-
returnCode = testAnalytics(appID, apiKey)
43+
returnCode = testAnalytics(ctx, appID, apiKey)
3744
case "insights":
38-
returnCode = testInsights(appID, apiKey)
45+
returnCode = testInsights(ctx, appID, apiKey)
3946
case "personalization":
40-
returnCode = testPersonalization(appID, apiKey)
47+
returnCode = testPersonalization(ctx, appID, apiKey)
4148
case "query-suggestions":
42-
returnCode = testQuerySuggestions(appID, apiKey)
49+
returnCode = testQuerySuggestions(ctx, appID, apiKey)
4350
case "recommend":
44-
returnCode = testRecommend(appID, apiKey)
51+
returnCode = testRecommend(ctx, appID, apiKey)
4552
default:
4653
fmt.Println("Please specify a valid client name")
4754
os.Exit(1)

playground/go/personalization.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import (
88
"github.com/algolia/algoliasearch-client-go/v4/algolia/next/personalization"
99
)
1010

11-
func testPersonalization(appID, apiKey string) int {
11+
func testPersonalization(ctx context.Context, appID, apiKey string) int {
1212
personalizationClient, err := personalization.NewClient(appID, apiKey, personalization.US)
1313
if err != nil {
1414
panic(err)
1515
}
16-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
16+
ctx, cancel := context.WithTimeout(ctx, 10*time.Millisecond)
1717
defer cancel()
1818

1919
// it will fail expectedly because of the very short timeout to showcase the context usage.
20-
deleteUserProfileResponse, err := personalizationClient.DeleteUserProfile("userToken", personalization.WithContext(ctx))
20+
deleteUserProfileResponse, err := personalizationClient.DeleteUserProfile(ctx, "userToken")
2121
if err != nil {
2222
fmt.Printf("request error with DeleteUserProfile: %v\n", err)
2323
return 1

playground/go/query-suggestions.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56

67
suggestions "github.com/algolia/algoliasearch-client-go/v4/algolia/next/query-suggestions"
78
)
89

9-
func testQuerySuggestions(appID, apiKey string) int {
10+
func testQuerySuggestions(ctx context.Context, appID, apiKey string) int {
1011
suggestionsClient, err := suggestions.NewClient(appID, apiKey, suggestions.US)
1112
if err != nil {
1213
panic(err)
1314
}
1415

15-
querySuggestionsIndex, err := suggestionsClient.GetAllConfigs()
16+
querySuggestionsIndex, err := suggestionsClient.GetAllConfigs(ctx)
1617
if err != nil {
1718
fmt.Printf("request error with GetAllConfigs: %v\n", err)
1819
return 1

playground/go/recommend.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56

67
"github.com/algolia/algoliasearch-client-go/v4/algolia/next/recommend"
78
)
89

9-
func testRecommend(appID, apiKey string) int {
10+
func testRecommend(ctx context.Context, appID, apiKey string) int {
1011
recommendClient, err := recommend.NewClient(appID, apiKey)
1112
if err != nil {
1213
panic(err)
@@ -27,7 +28,7 @@ func testRecommend(appID, apiKey string) int {
2728
},
2829
}}
2930

30-
searchResponse, err := recommendClient.GetRecommendations(params)
31+
searchResponse, err := recommendClient.GetRecommendations(ctx, params)
3132
if err != nil {
3233
fmt.Printf("request error with SearchSingleIndex: %v\n", err)
3334
return 1

playground/go/search.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56

67
"github.com/algolia/algoliasearch-client-go/v4/algolia/next/search"
78
)
89

9-
func testSearch(appID, apiKey string) int {
10+
func testSearch(ctx context.Context, appID, apiKey string) int {
1011
// indexName := getEnvWithDefault("SEARCH_INDEX", "test_index")
1112
searchClient, err := search.NewClient(appID, apiKey)
1213
if err != nil {
1314
panic(err)
1415
}
1516

16-
err = searchClient.BrowseObjects("test-flag", *search.NewEmptyBrowseParamsObject(), search.WithAggregator(func(res any, err error) {
17+
err = searchClient.BrowseObjects(ctx, "test-flag", *search.NewEmptyBrowseParamsObject(), search.WithAggregator(func(res any, err error) {
1718
if err != nil {
1819
panic(err)
1920
}
@@ -29,12 +30,12 @@ func testSearch(appID, apiKey string) int {
2930
//})))
3031

3132
// new way
32-
//searchClient.Search([]search.SearchQuery{
33+
//searchClient.Search(ctx, []search.SearchQuery{
3334
// search.NewSearchForHits("indexName").WithQuery("foo"),
3435
//}, nil)
3536

3637
/*
37-
response, err := searchClient.AddOrUpdateObject(
38+
response, err := searchClient.AddOrUpdateObject(ctx,
3839
searchClient.NewApiAddOrUpdateObjectRequest(
3940
indexName,
4041
"1",
@@ -49,12 +50,12 @@ func testSearch(appID, apiKey string) int {
4950
panic(err)
5051
}
5152
52-
_, err = searchClient.WaitForTask(indexName, *response.TaskID)
53+
_, err = searchClient.WaitForTask(ctx, indexName, *response.TaskID)
5354
if err != nil {
5455
panic(err)
5556
}
5657
57-
searchResponse, err := searchClient.Search(
58+
searchResponse, err := searchClient.Search(ctx,
5859
searchClient.NewApiSearchRequest(
5960
search.NewSearchMethodParams(
6061
[]search.SearchQuery{

0 commit comments

Comments
 (0)