Kuzzle blog

Go SDK released for Kuzzle v2

Written by Yoann Abbes | March 12, 2021

Our SDK catalog is growing for Kuzzle v2, and now it's Go's turn! 

This is the opportunity to let you discover our new SDK Go v3, which allows developers to use Kuzzle in the high performance environment of the Go ecosystem.

Why Go?

 

Created by Google, Go permits the production of extremely portable and powerful programs. Cross compilation is easy via its system of environment variables.

 

Go is also a productive language. The compiled program embeds its execution environment and a garbage collector. The syntax is verbose and explicit, making it easy to learn.

Go ensures that your toolbox stays compatible on all platforms and hardware, which is useful for DevOps.

It also uses a simple and portable package management solution. You can easily replace your scripting languages by Go.

Many open-source projects (Jaeger, Kubernetes, Docker, etc.) are now written in Go. 

It is becoming more and more useful as a standard language for microservices and the web.

 

Show me the code!

Install the SDK:

$ go get github.com/kuzzleio/sdk-go

 

Login now to your Kuzzle application!

 

First of all you have to instantiate the SDK by choosing the communication protocol.

 

  c := websocket.NewWebSocket("kuzzle", nil)
kuzzle, _ := kuzzle.NewKuzzle(c, nil)
err := kuzzle.Connect()
if err != nil {
log.Fatal(err)
os.Exit(1)
}
fmt.Println("Connected!")

 

The structure of our SDKs is based on our API with a division into controllers and actions.

To authenticate:

_, err := kuzzle.Auth.Login("local", json.RawMessage("{\"username\":\"foo\",\"password\":\"bar\"}"), nil)
if err != nil {
log.Fatal(err)
} else {
fmt.Printf("Success")
}

 

To create a document: 

response, err := kuzzle.Document.Create("nyc-open-data", "yellow-taxi", "some-id", json.RawMessage(`{"lastName": "Eggins"}`), nil)
if err != nil {
log.Fatal(err)
} else {
fmt.Println(string(response))
fmt.Println("Success")
}

 

 

You can consult the complete documentation  and discover our Getting Started 

A "Godoc" is also generated from Github via the comments we leave in the code https://pkg.go.dev/github.com/kuzzleio/sdk-go/ .

Join the Kuzzle + Go community

We will continue to expand the documentation to make it more accessible, including Getting Started and new guides.

Finally, as the Kuzzle API is constantly being enriched with new actions, we will also have work to integrate them into the current SDK.

We are open-source, so feel free to contribute ;) https://github.com/kuzzleio/sdk-go

If you have any questions about the SDK, you can ask the core-team on Stackoverflow or come and discuss it with the community on Discord: http://join.discord.kuzzle.io.