Documentation
¶
Overview ¶
Package hackernews is a dependency-free client for the official Hacker News Firebase API (https://hacker-news.firebaseio.com/v0/).
It uses only the Go standard library and builds with CGO_ENABLED=0.
Index ¶
- Constants
- type Client
- func (c *Client) BestStories(ctx context.Context) ([]int, error)
- func (c *Client) Item(ctx context.Context, id int) (*Item, error)
- func (c *Client) NewStories(ctx context.Context) ([]int, error)
- func (c *Client) Stories(ctx context.Context, kind StoryKind, limit int) ([]Item, error)
- func (c *Client) TopStories(ctx context.Context) ([]int, error)
- type Item
- type Option
- type StoryKind
Constants ¶
const DefaultBaseURL = "https://hacker-news.firebaseio.com/v0"
DefaultBaseURL is the base URL of the public Hacker News Firebase API.
const DefaultUserAgent = "go-hackernews/hackernews (+https://github.com/go-hackernews/hackernews)"
DefaultUserAgent is sent on every request unless overridden.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client is a Hacker News API client. Use New to construct one.
func New ¶
New returns a Client with sane defaults (the public API base URL and http.DefaultClient), then applies opts in order.
func (*Client) BestStories ¶
BestStories returns the IDs of the best stories.
func (*Client) NewStories ¶
NewStories returns the IDs of the newest stories.
type Item ¶
type Item struct {
ID int `json:"id"`
Type string `json:"type"` // "story","comment","job","poll",...
By string `json:"by"`
Time int64 `json:"time"` // unix seconds
Text string `json:"text"` // HTML, for text posts/comments
URL string `json:"url"` // external link for stories
Title string `json:"title"`
Score int `json:"score"`
Descendants int `json:"descendants"` // total comment count
Kids []int `json:"kids"`
Deleted bool `json:"deleted"`
Dead bool `json:"dead"`
}
Item is a Hacker News item: a story, comment, job, poll, or poll option.
type Option ¶
type Option func(*Client)
Option customizes a Client.
func WithBaseURL ¶
WithBaseURL overrides the API base URL (useful for testing).
func WithHTTPClient ¶
WithHTTPClient sets the underlying *http.Client.
func WithUserAgent ¶
WithUserAgent overrides the User-Agent header sent on each request.
type StoryKind ¶
type StoryKind string
StoryKind selects a story list.
const ( // Top selects the top stories list. Top StoryKind = "top" // Newest selects the newest stories list. // // NOTE: the required API named this constant "New", but that collides with // the New constructor function in the same package (an unavoidable Go name // clash), so it is exported as Newest. Its string value is still "new". Newest StoryKind = "new" // Best selects the best stories list. Best StoryKind = "best" )