Documentation
¶
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) FeedLabels() []string
- func (c *Client) FeedNames() []string
- func (c *Client) FetchCommentTree(item *Item, maxDepth int) ([]*Comment, error)
- func (c *Client) FetchComments(item *Item) ([]*Item, error)
- func (c *Client) FetchItem(id int) (*Item, error)
- func (c *Client) FetchItems(ids []int) ([]*Item, error)
- func (c *Client) FetchStoryIDs(feed string) ([]int, error)
- func (c *Client) Name() string
- func (c *Client) StoryURL(item *Item) string
- type Comment
- type Item
- type LobstersClient
- func (c *LobstersClient) FeedLabels() []string
- func (c *LobstersClient) FeedNames() []string
- func (c *LobstersClient) FetchCommentTree(item *Item, maxDepth int) ([]*Comment, error)
- func (c *LobstersClient) FetchItem(id int) (*Item, error)
- func (c *LobstersClient) FetchItems(ids []int) ([]*Item, error)
- func (c *LobstersClient) FetchStoryIDs(feed string) ([]int, error)
- func (c *LobstersClient) Name() string
- func (c *LobstersClient) StoryURL(item *Item) string
- type RedditClient
- func (c *RedditClient) FeedLabels() []string
- func (c *RedditClient) FeedNames() []string
- func (c *RedditClient) FetchCommentTree(item *Item, maxDepth int) ([]*Comment, error)
- func (c *RedditClient) FetchItem(id int) (*Item, error)
- func (c *RedditClient) FetchItems(ids []int) ([]*Item, error)
- func (c *RedditClient) FetchStoryIDs(feed string) ([]int, error)
- func (c *RedditClient) Name() string
- func (c *RedditClient) StoryURL(item *Item) string
- type Source
Constants ¶
const ( FeedTop = "topstories" FeedNew = "newstories" FeedBest = "beststories" FeedAsk = "askstories" FeedShow = "showstories" )
Feed types
const ( LobstersFeedHottest = "" // Default front page LobstersFeedNewest = "newest" // /newest LobstersFeedRecent = "recent" // /recent (recently active) )
Lobste.rs feed types (correspond to URL paths)
const ( RedditFeedHot = "hot" RedditFeedNew = "new" RedditFeedTop = "top" RedditFeedRising = "rising" RedditFeedBest = "best" )
Reddit feed types (correspond to URL paths)
Variables ¶
var LobstersFeedLabels = []string{"Hot", "New", "Recent"}
var LobstersFeedNames = []string{LobstersFeedHottest, LobstersFeedNewest, LobstersFeedRecent}
var RedditFeedLabels = []string{"Hot", "New", "Top", "Rising", "Best"}
var RedditFeedNames = []string{RedditFeedHot, RedditFeedNew, RedditFeedTop, RedditFeedRising, RedditFeedBest}
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the HN API client
func (*Client) FeedLabels ¶
FeedLabels returns the display labels for feeds
func (*Client) FetchCommentTree ¶
FetchCommentTree fetches the full comment tree for a story
func (*Client) FetchComments ¶
FetchComments fetches all comments for a story recursively
func (*Client) FetchItems ¶
FetchItems fetches multiple items concurrently
func (*Client) FetchStoryIDs ¶
FetchStoryIDs fetches the list of story IDs for a given feed
type Item ¶
type Item struct {
ID int `json:"id"`
Type string `json:"type"`
By string `json:"by"`
Time int64 `json:"time"`
Text string `json:"text"`
URL string `json:"url"`
Title string `json:"title"`
Score int `json:"score"`
Kids []int `json:"kids"`
Parent int `json:"parent"`
Descendants int `json:"descendants"`
Deleted bool `json:"deleted"`
Dead bool `json:"dead"`
}
Item represents a HN item (story, comment, job, poll)
type LobstersClient ¶
type LobstersClient struct {
// contains filtered or unexported fields
}
LobstersClient scrapes lobste.rs
func NewLobstersClient ¶
func NewLobstersClient() *LobstersClient
NewLobstersClient creates a new Lobste.rs scraping client
func (*LobstersClient) FeedLabels ¶
func (c *LobstersClient) FeedLabels() []string
FeedLabels returns the display labels for feeds
func (*LobstersClient) FeedNames ¶
func (c *LobstersClient) FeedNames() []string
FeedNames returns the available feed names
func (*LobstersClient) FetchCommentTree ¶
func (c *LobstersClient) FetchCommentTree(item *Item, maxDepth int) ([]*Comment, error)
FetchCommentTree fetches comments for a story
func (*LobstersClient) FetchItem ¶
func (c *LobstersClient) FetchItem(id int) (*Item, error)
FetchItem fetches a cached item by pseudo-ID
func (*LobstersClient) FetchItems ¶
func (c *LobstersClient) FetchItems(ids []int) ([]*Item, error)
FetchItems fetches multiple cached items by pseudo-ID
func (*LobstersClient) FetchStoryIDs ¶
func (c *LobstersClient) FetchStoryIDs(feed string) ([]int, error)
FetchStoryIDs fetches story "IDs" for a feed Since lobste.rs doesn't have numeric IDs, we fetch stories and cache them returning sequential pseudo-IDs
func (*LobstersClient) Name ¶
func (c *LobstersClient) Name() string
Name returns the display name of the source
func (*LobstersClient) StoryURL ¶
func (c *LobstersClient) StoryURL(item *Item) string
StoryURL returns the URL for viewing a story on Lobste.rs
type RedditClient ¶ added in v0.5.0
type RedditClient struct {
// contains filtered or unexported fields
}
RedditClient fetches data from Reddit's JSON API
func NewRedditClient ¶ added in v0.5.0
func NewRedditClient(subreddit string) *RedditClient
NewRedditClient creates a new Reddit API client for a subreddit
func (*RedditClient) FeedLabels ¶ added in v0.5.0
func (c *RedditClient) FeedLabels() []string
FeedLabels returns the display labels for feeds
func (*RedditClient) FeedNames ¶ added in v0.5.0
func (c *RedditClient) FeedNames() []string
FeedNames returns the available feed names
func (*RedditClient) FetchCommentTree ¶ added in v0.5.0
func (c *RedditClient) FetchCommentTree(item *Item, maxDepth int) ([]*Comment, error)
FetchCommentTree fetches comments for a story
func (*RedditClient) FetchItem ¶ added in v0.5.0
func (c *RedditClient) FetchItem(id int) (*Item, error)
FetchItem fetches a cached item by pseudo-ID
func (*RedditClient) FetchItems ¶ added in v0.5.0
func (c *RedditClient) FetchItems(ids []int) ([]*Item, error)
FetchItems fetches multiple cached items by pseudo-ID
func (*RedditClient) FetchStoryIDs ¶ added in v0.5.0
func (c *RedditClient) FetchStoryIDs(feed string) ([]int, error)
FetchStoryIDs fetches story "IDs" for a feed
func (*RedditClient) Name ¶ added in v0.5.0
func (c *RedditClient) Name() string
Name returns the display name of the source
func (*RedditClient) StoryURL ¶ added in v0.5.0
func (c *RedditClient) StoryURL(item *Item) string
StoryURL returns the URL for viewing a story on Reddit
type Source ¶
type Source interface {
// Name returns the display name of the source
Name() string
// FeedNames returns the available feed names for this source
FeedNames() []string
// FeedLabels returns the display labels for feeds (for UI tabs)
FeedLabels() []string
// FetchStoryIDs fetches the list of story IDs for a given feed
// For sources without IDs (like Lobste.rs), this returns page-based pseudo-IDs
FetchStoryIDs(feed string) ([]int, error)
// FetchItem fetches a single item by ID
FetchItem(id int) (*Item, error)
// FetchItems fetches multiple items by ID
FetchItems(ids []int) ([]*Item, error)
// FetchCommentTree fetches the comment tree for a story
FetchCommentTree(item *Item, maxDepth int) ([]*Comment, error)
// StoryURL returns the URL for viewing a story on the source's website
StoryURL(item *Item) string
}
Source represents a news source (HN, Lobste.rs, etc.)