Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(go): update go docs #2200

Merged
merged 7 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,42 @@ UpdatedAtResponse response = client.operationIndex(
client.waitForTask("<SOURCE_INDEX_NAME>", response.getTaskID());
```

</TabItem>
<TabItem value="go">

```go
import (
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)

indexName := "<SOURCE_INDEX_NAME>"
appID := "<APPLICATION_ID>"
apiKey := "<API_KEY>"

searchClient := search.NewClient(appID, apiKey)

operationIndexRequest := searchClient.NewApiOperationIndexRequest(
indexName,
search.NewOperationIndexParams(search.OPERATIONTYPE_COPY, "<DESTINATION_INDEX_NAME>"),
)

operationIndex, err := searchClient.OperationIndex(operationIndexRequest)
if err != nil {
panic(err)
}

taskResponse, err := searchClient.WaitForTask(
indexName,
operationIndex.TaskID,
nil,
nil,
nil,
)
if err != nil {
panic(err)
}
```

</TabItem>

<TabItem value="kotlin">
Expand Down Expand Up @@ -212,9 +248,41 @@ await client.waitTask('<SOURCE_INDEX_NAME>', response.taskID);
```

</TabItem>

<TabItem value="go">
// TBD

```go
import (
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)

indexName := "<SOURCE_INDEX_NAME>"
appID := "<APPLICATION_ID>"
apiKey := "<API_KEY>"

searchClient := search.NewClient(appID, apiKey)

operationIndexRequest := searchClient.NewApiOperationIndexRequest(
indexName,
search.NewOperationIndexParams(search.OPERATIONTYPE_MOVE, "<DESTINATION_INDEX_NAME>"),
)

operationIndex, err := searchClient.OperationIndex(operationIndexRequest)
if err != nil {
panic(err)
}

taskResponse, err := searchClient.WaitForTask(
indexName,
operationIndex.TaskID,
nil,
nil,
nil,
)
if err != nil {
panic(err)
}
```

</TabItem>
</TabsLanguage>

Expand Down Expand Up @@ -322,6 +390,43 @@ await client.waitTask('<SOURCE_INDEX_NAME>', response.taskID);
</TabItem>

<TabItem value="go">
// TBD

```go
import (
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)

indexName := "<SOURCE_INDEX_NAME>"
appID := "<APPLICATION_ID>"
apiKey := "<API_KEY>"

searchClient := search.NewClient(appID, apiKey)

operationIndexRequest := searchClient.NewApiOperationIndexRequest(
indexName,
search.NewOperationIndexParams(
search.OPERATIONTYPE_MOVE,
"<DESTINATION_INDEX_NAME>",
search.WithOperationIndexParamsScope([]search.ScopeType{search.SCOPETYPE_RULES}),
),
)

operationIndex, err := searchClient.OperationIndex(operationIndexRequest)
if err != nil {
panic(err)
}

taskResponse, err := searchClient.WaitForTask(
indexName,
operationIndex.TaskID,
nil,
nil,
nil,
)
if err != nil {
panic(err)
}
```

</TabItem>
</TabsLanguage>
109 changes: 103 additions & 6 deletions website/docs/clients/guides/customized-client-usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ val client = SearchClient(
)
)
```

</TabItem>

<TabItem value="dart">
Expand All @@ -65,7 +64,15 @@ var client = SearchClient(
</TabItem>

<TabItem value="go">
// TBD
If you enable the `debug` property of the Go API client, it will print the request and response to the standard output.

```go
searchClient := search.NewClientWithConfig(search.Configuration{
AppID: "<YOUR_APP_ID>",
ApiKey: "<YOUR_API_KEY>",
Debug: true,
})
```
</TabItem>
</TabsLanguage>

Expand Down Expand Up @@ -199,7 +206,38 @@ await client.search(
</TabItem>

<TabItem value="go">
// TBD

```go
import (
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)

indexName := "<INDEX_NAME>"
appID := "<APPLICATION_ID>"
apiKey := "<API_KEY>"

searchClient := search.NewClient(appID, apiKey)

searchClient.Search(
searchClient.NewApiSearchRequest(
search.NewSearchMethodParams([]search.SearchQuery{
search.SearchForHitsAsSearchQuery(
search.NewSearchForHits(
indexName,
search.WithSearchForHitsQuery("jeans"),
search.WithSearchForHitsHitsPerPage(50),
),
),
}),
),
// This header is added to the request
search.HeaderParamOption("additional-header", "hello"),

// As we re-define `hitsPerPage`, it will override the value defined in the method's parameters.
search.QueryParamOption("hitsPerPage", 100),
)
```

</TabItem>
</TabsLanguage>

Expand Down Expand Up @@ -295,7 +333,28 @@ var client = SearchClient(
</TabItem>

<TabItem value="go">
// TBD

> In the Go client, you can use the NewClientWithConfig method to create a new API client with the given configuration to fully customize the client behaviour. Only the AppID and APIKey are required, other configuration parameters will be defaulted if not provided.

```go
import (
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)

searchClient := search.NewClientWithConfig(search.Configuration{
AppID: appID,
ApiKey: apiKey,
Hosts: nil,
DefaultHeader: nil,
UserAgent: "my user agent (optional version)",
Debug: false,
Requester: nil,
ReadTimeout: 0,
WriteTimeout: 0,
Compression: 0,
})
```

</TabItem>
</TabsLanguage>

Expand Down Expand Up @@ -385,8 +444,46 @@ var client = SearchClient(
```

</TabItem>

<TabItem value="go">
// TBD

> In the Go client, you can use the NewClientWithConfig method to create a new API client with the given configuration to fully customize the client behaviour. Only the AppID and APIKey are required, other configuration parameters will be defaulted if not provided.

```go
import (
"net/http"

"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)

type MyCustomRequester struct {
client *http.Client
}

func NewCustomRequester() *MyCustomRequester {
return &MyCustomRequester{
client: http.DefaultClient,
}
}

func (r *MyCustomRequester) Request(req *http.Request) (*http.Response, error) {
println("MyCustomRequester > Request: ", req.RequestURI)

return r.client.Do(req)
}

searchClient := search.NewClientWithConfig(search.Configuration{
AppID: appID,
ApiKey: apiKey,
Hosts: nil,
DefaultHeader: nil,
UserAgent: "",
Debug: false,
Requester: NewCustomerRequester(),
ReadTimeout: 0,
WriteTimeout: 0,
Compression: 0,
})
```

</TabItem>
</TabsLanguage>
45 changes: 44 additions & 1 deletion website/docs/clients/guides/delete-objects.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,50 @@ await client.batch(
</TabItem>

<TabItem value="go">
// TBD

```go
import (
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)

indexName := "<INDEX_NAME>"
appID := "<APPLICATION_ID>"
apiKey := "<API_KEY>"

searchClient := search.NewClient(appID, apiKey)

objectIDs := []string{"1", "2", "3", "4", "5"}
batchRequests := make([]search.BatchRequest, 0, len(objectIDs))

for _, objectID := range objectIDs {
batchRequests = append(
batchRequests,
*search.NewBatchRequest(search.ACTION_DELETE, map[string]any{"objectID": objectID}),
)
}

batchWriteParams := search.NewBatchWriteParams(batchRequests)

batchResponse, err := searchClient.Batch(searchClient.NewApiBatchRequest(
indexName,
batchWriteParams,
))
if err != nil {
panic(err)
}

taskResponse, err := searchClient.WaitForTask(
indexName,
batchResponse.TaskID,
nil,
nil,
nil,
)
if err != nil {
panic(err)
}
```

</TabItem>
</TabsLanguage>

Expand Down
Loading