Announcing the Square Go SDK

Announcing the Square Go SDK

Easier Square integrations with your Go backend

It’s Time to Get ‘Go’ing

After much anticipation, and many asks from our community, we are very excited to announce Square now has a Go SDK! For Go SDK details, please visit our website. If you are looking to get started quickly with the SDK, please check out this quick-start guide.

The Go SDK in a Nutshell

If you are already familiar with our other SDKs, you will recognize many similarities between those and our Go SDK – however, our SDK was built to be idiomatic with Go, which will make the integration feel natural for your project.

A Few Highlights

  • Dependency Free - This SDK is built completely on top of the standard library and fully compatible with net/http libraries.
  • Auto-Pagination - With the SDK, you can easily paginate through long responses. Read more here.
  • Request Retries - The SDK will handle request retries for you, as well as allow you to alter the retry strategy.

Our Go SDK is composed of many clients (based on our available APIs) which are all branched off of a general square.Client.

SDK Usage

Install the Go SDK to your project with:

go get github.com/square/square-go-sdk

You can then initialize the square.Client in your code like the following sample.

import (
    "fmt"
    "context"

    square "github.com/square/square-go-sdk"
    squareclient "github.com/square/square-go-sdk/client"
    "github.com/square/square-go-sdk/option"
)

client := squareclient.NewClient(
    option.WithToken("<YOUR_ACCESS_TOKEN>"),
    // defaults to the production environment
    option.WithBaseURL("https://connect.squareupsandbox.com")
)

From here, our new variable client has access to the other API clients that compose this SDK. For example, requesting to see the locations for a given access token would like like this:

response, err := client.Locations.List(context.TODO())

fmt.Println(*response.Locations[0].ID)

Check out our API Explorer to generate code examples in Go for any of our APIs you are interested in using.

What’s Next?

We are so excited to see what you build with the Go SDK, and we want to hear your feedback! Please submit feedback to our forums, Discord, or on the Github repository's issues. Happy coding!

Table Of Contents