l4u / algoliasearch-client-go

Algolia Search API Client for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Algolia for Go

The perfect starting point to integrate Algolia within your Go project

Build Status Github Releases GoDoc Go Report Card License Supported version

DocumentationCommunity ForumStack OverflowReport a bugSupport

✨ Features

  • Support Go 1.8 and above
  • Typed requests and responses
  • First-class support for user-defined structures
  • Injectable HTTP client

Migration note from v2.x to v3.x

In June 2019, we released v3 of our Go client. If you are using version 2.x of the client, read the migration guide to version 3.x. Version 2.x will no longer be under active development.

💡 Getting Started

First, add the Algolia Go API Client as a new module to your Go project:

# First line is optional if your project is already defined as a Go module
go mod init <YOUR_PROJECT_NAME>
go get github.com/algolia/algoliasearch-client-go/v3@v3.4.0

Then, create objects on your index:

package main

import "github.com/algolia/algoliasearch-client-go/v3/algolia/search"

type Contact struct {
	ObjectID string `json:"objectID"`
	Name     string `json:"name"`
}

func main() {
	client := search.NewClient("YourApplicationID", "YourAPIKey")
	index := client.InitIndex("your_index_name")

	res, err := index.SaveObjects([]Contact{
		{ObjectID: "1", Name: "Foo"},
	})
}

Finally, you may begin searching a object using the Search method:

package main

import (
	"fmt"
	"os"

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

type Contact struct {
	ObjectID string `json:"objectID"`
	Name     string `json:"name"`
}

func main() {
	client := search.NewClient("YourApplicationID", "YourAPIKey")
	index := client.InitIndex("your_index_name")

	res, err := index.Search("Foo")
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	var contacts []Contact

	err = res.UnmarshalHits(&contacts)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	fmt.Println(contacts)
}

For full documentation, visit the Algolia Go API Client.

📄 License

Algolia Go API Client is an open-sourced software licensed under the MIT license.

About

Algolia Search API Client for Go

License:MIT License


Languages

Language:Go 99.5%Language:Shell 0.3%Language:Makefile 0.1%