The go-twitch library is a complete interface for Twitch services. It is designed to be easy to use and allows for easy integration into any project.
The library provides access to the Twitch API in order to manage and retrieve information about Twitch resources, users, streams, and more.
The documentation for each API call includes a link to the related Twitch Developer Documentation, making it easy to find related information.
Where possible, required fields are enforced by the call initializers, making it easier to use the API correctly.
Important
In some cases, such as where at only one of multiple fields is required, enforcement may not be available. For this reason, it is recommended to refer to the documentation to ensure correct usage.
When writing tests for code that uses the Twitch API, it is often useful to mock the API responses. For this reason, the apitest package is included to facilitate easy mocking of Twitch API responses.
To use, provide the mocks HTTP client using the api.WithHTTPClient option. Failing to set the HTTP client will result in th API request being sent to Twitch.
Fetch all current livestreams
package main
import (
"context"
"fmt"
"github.com/adeithe/go-twitch/api"
)
const (
ClientID = "wbmytr93xzw8zbg0p1izqyzzc5mbiz"
OAuthToken = "2gbdx6oar67tqtcmt49t3wpcgycthx"
)
func main() {
ctx := context.Background()
client := api.NewClient(ClientID)
var cursor string
req := client.Streams.List().First(100)
for {
streams, err := req.After(cursor).Do(ctx, api.WithBearerToken(OAuthToken))
if err != nil {
panic(err)
}
if len(streams.Data) == 0 {
break
}
for _, stream := range streams.Data {
fmt.Printf("%s is streaming %s to %d viewers\n",
stream.UserLogin,
stream.GameName,
stream.ViewerCount,
)
}
cursor = streams.Pagination.Cursor
}
}In accordance with the Go Project's Supported Versions Policy, each Go release is supported until there are two newer major releases. After this period, support for older versions may be dropped in future releases.
If you find a bug, please open an issue on the GitHub Issues Page.
For general questions or support, visit the go-twitch Discord channel.