hermanschaaf / hackernews

Modern Go client for the Hacker News API
MIT License
3 stars 0 forks source link

Hacker News API Go Client

Go Reference

This is an up-to-date Go client for the Hacker News API.

Installation

go get github.com/hermanschaaf/hackernews

Usage

package main

import (
    "context"
    "fmt"
    "log"

    "github.com/hermanschaaf/hackernews"
)

func main() {
    client := hackernews.NewClient()
    ctx := context.Background()

    // Get the top 10 stories
    topStories, err := client.TopStories(ctx)
    if err != nil {
        log.Fatal(err)
    }

    // Print the title of the first story
    story, err := client.GetItem(ctx, topStories[0])
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(story.Title)
}