twitch

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package twitch fetches live streams, categories, and channels from Twitch via the public GQL API.

Index

Constants

View Source
const (
	DefaultUserAgent = "Mozilla/5.0 (compatible; twitch-cli/dev; +https://github.com/tamnd/twitch-cli)"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category struct {
	Rank    int    `json:"rank"    csv:"rank"    tsv:"rank"`
	ID      string `json:"id"      csv:"id"      tsv:"id"`
	Name    string `json:"name"    csv:"name"    tsv:"name"`
	Slug    string `json:"slug"    csv:"slug"    tsv:"slug"`
	Viewers int    `json:"viewers" csv:"viewers" tsv:"viewers"`
	URL     string `json:"url"     csv:"url"     tsv:"url"`
}

Category is a Twitch game/category.

type Channel

type Channel struct {
	Rank        int    `json:"rank"         csv:"rank"         tsv:"rank"`
	ID          string `json:"id"           csv:"id"           tsv:"id"`
	Login       string `json:"login"        csv:"login"        tsv:"login"`
	DisplayName string `json:"display_name" csv:"display_name" tsv:"display_name"`
	URL         string `json:"url"          csv:"url"          tsv:"url"`
}

Channel is a Twitch channel.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the Twitch GQL API.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client with the given configuration.

func (*Client) Categories

func (c *Client) Categories(ctx context.Context, limit int) ([]Category, error)

Categories returns the top categories/games by viewer count.

func (*Client) SearchChannels

func (c *Client) SearchChannels(ctx context.Context, query string) ([]Channel, error)

Search searches for channels and games matching the query.

func (*Client) Streams

func (c *Client) Streams(ctx context.Context, game string, limit int) ([]Stream, error)

Streams returns the top live streams, optionally filtered by game name.

type Config

type Config struct {
	BaseURL   string
	ClientID  string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
	UserAgent string
}

Config holds all tuneable client parameters.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for the Twitch GQL API.

type Stream

type Stream struct {
	Rank      int    `json:"rank"       csv:"rank"       tsv:"rank"`
	ID        string `json:"id"         csv:"id"         tsv:"id"`
	Title     string `json:"title"      csv:"title"      tsv:"title"`
	Game      string `json:"game"       csv:"game"       tsv:"game"`
	Channel   string `json:"channel"    csv:"channel"    tsv:"channel"`
	Viewers   int    `json:"viewers"    csv:"viewers"    tsv:"viewers"`
	StartedAt string `json:"started_at" csv:"started_at" tsv:"started_at"`
	URL       string `json:"url"        csv:"url"        tsv:"url"`
}

Stream is a live Twitch stream.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL