hackernews

package
v0.2.1 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: 12 Imported by: 0

Documentation

Overview

Package hackernews is the library behind the hackernews command: the HTTP client, pacing, and the typed data models for the Hacker News Firebase API.

The official Firebase endpoint at hacker-news.firebaseio.com is open: no API key, no auth, no rate limits beyond basic politeness. This package wraps it with a sequential, rate-limited client that the kit operations consume.

Index

Constants

View Source
const (
	DefaultUserAgent = "hackernews/dev (+https://github.com/tamnd/hackernews-cli)"
)
View Source
const Host = "hacker-news.firebaseio.com"

Host is the Firebase base hostname for the Hacker News API.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when the Firebase API returns null for an id or user.

Functions

This section is empty.

Types

type Client

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

Client is a rate-limited HTTP client for the HN Firebase API.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) AskStories added in v0.2.0

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

AskStories fetches the Ask HN stories list and resolves up to limit items.

func (*Client) BestStories added in v0.2.0

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

BestStories fetches the best stories list and resolves up to limit items.

func (*Client) GetItem added in v0.2.0

func (c *Client) GetItem(ctx context.Context, id int) (*Item, error)

GetItem fetches a single item by id.

func (*Client) GetUser added in v0.2.0

func (c *Client) GetUser(ctx context.Context, id string) (*User, error)

GetUser fetches a single user profile by username.

func (*Client) JobStories added in v0.2.0

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

JobStories fetches the job stories list and resolves up to limit items.

func (*Client) NewStories added in v0.2.0

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

NewStories fetches the new stories list and resolves up to limit items.

func (*Client) ShowStories added in v0.2.0

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

ShowStories fetches the Show HN stories list and resolves up to limit items.

func (*Client) TopStories added in v0.2.0

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

TopStories fetches the top stories list and resolves up to limit items.

type Config

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

Config holds constructor parameters for Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for the Firebase API.

type Domain added in v0.2.0

type Domain struct{}

Domain is the Hacker News driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify added in v0.2.0

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (uriType, id). Numeric input → ("item", id); username-like → ("user", input); otherwise error.

func (Domain) Info added in v0.2.0

func (Domain) Info() kit.DomainInfo

Info describes the scheme and the identity the single-site binary inherits.

func (Domain) Locate added in v0.2.0

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the canonical HN URL for a (uriType, id).

func (Domain) Register added in v0.2.0

func (Domain) Register(app *kit.App)

Register installs the client factory and the five HN operations onto app.

type Item added in v0.2.0

type Item struct {
	ID          int    `kit:"id" json:"id"`
	Type        string `json:"type"`
	By          string `json:"by"`
	Time        int64  `json:"time"`
	Title       string `json:"title"`
	URL         string `json:"url"`
	Score       int    `json:"score"`
	Descendants int    `json:"descendants"`
	Kids        []int  `json:"kids"`
	Text        string `json:"text"`
	Dead        bool   `json:"dead"`
	Deleted     bool   `json:"deleted"`
}

Item is one record from the Firebase item endpoint. It covers stories, comments, Ask HN, Show HN, jobs, and polls.

type User

type User struct {
	ID      string `kit:"id" json:"id"`
	About   string `json:"about"`
	Karma   int    `json:"karma"`
	Created int64  `json:"created"`
}

User is one record from the Firebase user endpoint.

Jump to

Keyboard shortcuts

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