Weaviate provides a powerful Go client for Go developers which allows us to connect and interact with the Weaviate cluster using the Go programming language.
This tutorial covers the fundamentals of installing, configuring, and using this client to perform various actions on the Weaviate cluster.
Prerequisites:
- Golang compiler – Ensure that you install the latest Go compiler on your machine before proceeding.
- Weaviate server – You also need a running instance of the Weaviate server. You can set up a local cluster using Docker and Kubernetes or a cloud-hosted instance.
With the given requirements met, we can proceed to the installation process.
Install the Weaviate Go Client
The first step is installing the Weaviate Go client. You can do this using the “go get” command as shown in the following:
This should download the latest stable version of the Weaviate Go client on your machine.
Connect to the Weaviate Server
To use the Weaviate client, import the client library first and create a new client object.
import (
"context"
"fmt"
"github.com/weaviate/weaviate-go-client/v4/weaviate"
)
func main() {}
cfg := weaviate.Config{
Host: "localhost:8080",
Scheme: "http",
}
client, err := weaviate.NewClient(cfg)
if err != nil {
panic(err)
}
}
In the given example, we start by importing the required packages. In this case, we need the context, fmt, and the Weaviate packages.
Once imported, we use the Weaviate package to initialize a new client with the specified configuration.
Conclusion
We covered how you can quickly configure your Go application to connect to the Weaviate cluster.