Installation

go get github.com/GetStream/getstream-go/v4@v4.0.6

Use the latest available SDK release when starting a new integration.
Check getstream-go releases and replace the version if a newer one is available.

GitHub repository: https://github.com/GetStream/getstream-go. Feel free to submit bug reports and feature requests.

The package is tested against these environments:

  • Go 1.19+
  • Go 1.20+
  • Go 1.21+

To create a client, you'll need your API key and secret. Both of them can be found in your Stream Dashboard.

You can optionally configure request timeouts and the HTTP connection pool. The default request timeout is 30 seconds (30000ms).

package main

import (
    "context"
    "log"
    "time"

    "github.com/GetStream/getstream-go/v4"
)

func main() {
    apiKey := ""
    secret := ""

    client, err := getstream.NewClient(apiKey, secret)
    if err != nil {
        log.Fatal(err)
    }

    // optionally override the per-request timeout (default is 30s)
    client, err = getstream.NewClient(apiKey, secret, getstream.WithRequestTimeout(30*time.Second))
    if err != nil {
        log.Fatal(err)
    }

    // Get the feeds client
    feedsClient := client.Feeds()

    ctx := context.Background()

    // Your feeds operations here...
}

Connection pool and timeouts

By default the SDK uses an HTTP connection pool with keep-alive enabled. You can tune it with functional options:

OptionDefaultDescription
WithRequestTimeout (alias WithTimeout)30sPer-request timeout. Override per call with context.WithTimeout.
WithMaxConnsPerHost5Maximum concurrent connections per host.
WithIdleTimeout55sHow long idle connections stay in the pool.
WithConnectTimeout10sTCP + TLS handshake timeout.
client, err := getstream.NewClient(
    apiKey, secret,
    getstream.WithMaxConnsPerHost(10),
    getstream.WithIdleTimeout(55*time.Second),
    getstream.WithConnectTimeout(10*time.Second),
    getstream.WithRequestTimeout(30*time.Second),
)

You can also set the request timeout (in seconds) with the STREAM_HTTP_TIMEOUT environment variable.

To take full control of the HTTP stack, provide your own client with WithHTTPClient. When set, the pool options above are not applied:

client, err := getstream.NewClient(apiKey, secret, getstream.WithHTTPClient(myHTTPClient))