A robust, production-ready Go client library for the Gronkh.TV API. This library provides easy access to video information, comments, playlists, discovery features, and Twitch live status.
- 🚀 Simple and intuitive API - Easy-to-use client with clear method names
- 🔄 Automatic retry logic - Built-in retry with exponential backoff for resilient API calls
- ⏱️ Context support - Full context support for cancellation and timeouts
- 📝 Comprehensive documentation - Complete GoDoc comments for all public APIs
- âś… Well-tested - High test coverage with unit and integration tests
- 🛡️ Type-safe - Strongly typed responses with proper error handling
- 🔍 Request logging - Optional debug logging for troubleshooting
go get github.com/wehmoen-dev/gtvapi- Go 1.20 or higher
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/wehmoen-dev/gtvapi"
)
func main() {
// Create a new client
client := gtvapi.NewClient(nil)
// Set a timeout context
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Get video information
videoInfo, err := client.VideoInfo(ctx, 1000)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Video: %s (Episode %d)\n", videoInfo.Title, videoInfo.Episode)
fmt.Printf("Views: %d\n", videoInfo.Views)
}client := gtvapi.NewClient(nil)config := >vapi.ClientConfig{
Debug: true, // Enable debug logging
Timeout: 30 * time.Second, // Request timeout
MaxRetries: 3, // Maximum retry attempts
RetryWaitMin: 1 * time.Second, // Minimum wait between retries
RetryWaitMax: 30 * time.Second, // Maximum wait between retries
}
client := gtvapi.NewClient(config)ctx := context.Background()
videoInfo, err := client.VideoInfo(ctx, 1000)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Title: %s\n", videoInfo.Title)
fmt.Printf("Season: %d, Episode: %d\n", videoInfo.Season, videoInfo.Episode)
fmt.Printf("Duration: %d seconds\n", videoInfo.SourceLength)ctx := context.Background()
comments, err := client.VideoComments(ctx, 1000)
if err != nil {
log.Fatal(err)
}
for _, comment := range comments {
fmt.Printf("%s: %s\n", comment.User.Username, comment.Comment)
}ctx := context.Background()
playlistURL, err := client.VideoPlaylist(ctx, 1000)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Playlist URL: %s\n", playlistURL)ctx := context.Background()
// Get most recent videos
recent, err := client.Discover(ctx, gtvapi.DiscoveryTypeRecent)
if err != nil {
log.Fatal(err)
}
// Get most viewed videos
popular, err := client.Discover(ctx, gtvapi.DiscoveryTypeViews)
if err != nil {
log.Fatal(err)
}
// Get similar videos
similar, err := client.Discover(ctx, gtvapi.DiscoveryTypeSimilar)
if err != nil {
log.Fatal(err)
}ctx := context.Background()
tags, err := client.AllTags(ctx)
if err != nil {
log.Fatal(err)
}
for _, tag := range tags {
fmt.Printf("Tag #%d: %s\n", tag.ID, tag.Title)
}ctx := context.Background()
channels, err := client.LiveCheck(ctx)
if err != nil {
log.Fatal(err)
}
for name, info := range channels {
if info.IsLive {
fmt.Printf("%s is live! Viewers: %d\n", name, info.ViewerCount)
fmt.Printf("Playing: %s\n", info.GameName)
}
}Creates a new Gronkh.TV API client with optional configuration.
Retrieves detailed information about a specific video episode.
Fetches all comments for a specific video episode.
Gets the playlist URL for streaming a specific video episode.
Discovers videos based on the specified discovery type (recent, views, or similar).
Retrieves all available video tags.
Checks the live status of Twitch channels associated with Gronkh.TV.
See the GoDoc for detailed type definitions and field descriptions.
The library provides structured error handling:
videoInfo, err := client.VideoInfo(ctx, 1000)
if err != nil {
// Check for specific error types
if errors.Is(err, context.DeadlineExceeded) {
log.Println("Request timed out")
} else if errors.Is(err, context.Canceled) {
log.Println("Request was canceled")
} else {
log.Printf("API error: %v", err)
}
return
}- Always use context - Pass context to all API methods for proper timeout and cancellation handling
- Set reasonable timeouts - Configure appropriate timeouts based on your use case
- Handle errors properly - Check and handle all errors returned by the API
- Reuse clients - Create one client and reuse it for multiple requests
- Enable retry logic - Use the built-in retry mechanism for production environments
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Run the test suite:
# Run all tests
go test -v ./...
# Run tests with coverage
go test -v -cover ./...
# Run tests with race detection
go test -v -race ./...
# Run benchmarks
go test -bench=. ./...This project is licensed under the MIT License - see the LICENSE file for details.
For questions, issues, or feature requests, please open an issue on GitHub.