### Install the Algolia API Go Client via go get command Source: https://github.com/algolia/algoliasearch-client-go/blob/main/README.md Use this command to install the library version 4.x. This README says it supports Go 1. (The badge says >=1.0, but the features section says support for 19 and above; features say support for 2 1.19 and above, but the badge says >=1.codeSnippets[0].description: string was not supplied: ```bash go get github.com/bash ``` -------------------------------- ### Import and use the Algolia client to add and search for a record Source: https://github.com/algolia/algoliasearch-client-go/blob/main/README.md This example shows the basic usage of the client: create a client with your app ID and API key, save a simple record, wait for the task to finish, and then perform a search with a query and 50 hits per page. It uses the `search.NewClient` and `client.NewApiSearchRequest` APIs and assumes you replace the placeholder values (YOUR_ codeSnippets, YOUR_API_KEY, etc.). Note: the code uses `search.SearchQuery` and `search.SearchForHitsAsQuery, and the search call uses `client.Search` with a request built with `search.NewEmptySearchMethodParams` and `search.SearchForHisaAsQuery` — wait, I need to copy exactly as in source exactly as in source.codeSnippets[0].description: string was not supplied. Please provide a concise description for the install command snippet. Please provide a concise description for the described in the schema. Please provide a brief description for the install command. Please provide a concise description for the install command snippet.codeSIPpp. Please provide a concise description for the `go get` command snippet.description: string was not supplied. Please provide a concise description for the install command. Please provide a concise description for ther. Please provide acodeSIPpp. Please provide a concise description for the install command. Please provide a concise description for ther. Please provide a concise description for the install command. Please provide a concise description for ther. Please provide a concise description for ther. Please provide a concise description for ther.. . . . . . . . . . . . . . . codeSnippets[0].description: string was ```bash go get github.com/algolia/incorrect ``` -------------------------------- ### Build and Test Commands Source: https://github.com/algolia/algoliasearch-client-go/blob/main/AGENTS.md Commands to build, test, and lint the Go client. Run from repo root for yarn commands, or from the client directory for go commands. ```bash # From repo root (api-clients-automation) yarn cli build clients go # Build Go client yarn cli cts generate go # Generate CTS tests yarn cli cts run go # Run CTS tests yarn cli playground go search # Interactive playground yarn cli format go clients/algoliasearch-client-go # From client directory cd clients/algoliasearch-client-go go build ./... # Build all packages go test ./... # Run tests golangci-lint run # Run linter ``` -------------------------------- ### Module Path with Version Source: https://github.com/algolia/algoliasearch-client-go/blob/main/AGENTS.md The import path includes the version v4. Use this path when importing the search package. ```go // Import path includes version import "github.com/algolia/algoliasearch-client-go/v4/algolia/search" ``` -------------------------------- ### Verify repository remote Source: https://github.com/algolia/algoliasearch-client-go/blob/main/AGENTS.md Run this command first to confirm you are in the correct repository. If the remote shows 'algolia/api-clients-automation.git', you may proceed; if it shows 'algolia/algoliasearch-client-go.git', stop and do not make changes. ```bash git remote -v ``` -------------------------------- ### Context Usage with Cancellation and Timeout Source: https://github.com/algolia/algoliasearch-client-go/blob/main/AGENTS.md Always pass a context for cancellation. Use context.Background() for a base context, or context.WithTimeout to add a timeout. The response and error are returned from client.Search. ```go // Always pass context for cancellation ctx := context.Background() response, err := client.Search(ctx, params) // With timeout ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() response, err := client.Search(ctx, params) ``` -------------------------------- ### Error Checking with errors.As and APIError Source: https://github.com/algolia/algoliasearch-client-go/blob/main/AGENTS.md Always check errors from client.Search. Use errors.As to detect *errs.APIError and handle API-specific errors. Do not ignore errors. ```go // ALWAYS check errors response, err := client.Search(ctx, params) if err != nil { // Handle error - don't ignore! var apiErr *errs.APIError if errors.As(err, &apiErr) { // Handle API error } return err } ``` -------------------------------- ### Check generated file patterns in generation.config.mjs Source: https://github.com/algolia/algoliasearch-client-go/blob/main/AGENTS.md Inspect the patterns in 'config/generation.config.mjs'. Patterns without '!' are generated and must not be edited; patterns with '!' are hand-written and safe to edit. ```javascript // In generation.config.mjs - patterns WITHOUT '!' are GENERATED (do not edit) 'clients/algoliasearch-client-go/algolia/**', // Generated '!clients/algoliasearch-client-go/algolia/transport/**', // Hand-written ✓ '!clients/algoliasearch-client-go/algolia/errs/**', // Hand-written ✓ ``` -------------------------------- ### JSON Marshaling with json Tags Source: https://github.com/algolia/algoliasearch-client-go/blob/main/AGENTS.md Models use json tags for marshaling. Custom marshaling is done in model files; do not modify generated code. ```go // Models use json tags type Hit struct { ObjectID string `json:"objectID"` } // Custom marshaling in model files - don't modify generated code ``` -------------------------------- ### Error handling: ErrUnreachableHosts and APIError Source: https://github.com/algolia/algoliasearch-client-go/blob/main/AGENTS.md Declares the sentinel error ErrUnreachableHosts and the APIError struct with Status and Message fields. Use these for consistent error handling across the client. ```go // algolia/errs/ var ( ErrUnreachableHosts = errors.New("all hosts are unreachable") ) type APIError struct { Status int Message string } ``` -------------------------------- ### Pointer vs Value for Optional Fields Source: https://github.com/algolia/algoliasearch-client-go/blob/main/AGENTS.md Use pointers for optional struct fields. The utils.ToPtr helper from the algolia/utils package converts a value to a pointer. Query is required, HitsPerPage is optional. ```go // Use pointers for optional fields in structs type SearchParams struct { Query string // Required HitsPerPage *int // Optional - use utils.ToPtr(10) } // Helper in algolia/utils/ import "github.com/algolia/algoliasearch-client-go/v4/algolia/utils" params := SearchParams{ HitsPerPage: utils.ToPtr(10), } ``` -------------------------------- ### Requester interface Source: https://github.com/algolia/algoliasearch-client-go/blob/main/AGENTS.md Defines the Requester interface with a single Request method. The default implementation uses http.Client, but the interface is injectable for testing purposes. ```go type Requester interface { Request(req *http.Request) (*http.Response, error) } // Default uses http.Client, but injectable for testing ``` -------------------------------- ### Transport struct and constructor Source: https://github.com/algolia/algoliasearch-client-go/blob/main/AGENTS.md Defines the core transport type with requester, retry strategy, compression, and connect timeout fields. The New function accepts a Configuration to create a Transport with configurable requester, timeouts, and compression. ```go // Core transport in algolia/transport/ type Transport struct { requester Requester retryStrategy *RetryStrategy compression compression.Compression connectTimeout time.Duration } func New(cfg Configuration) *Transport { // Configurable requester, timeouts, compression } ```