hackernews

package
v0.0.0-...-8a3d196 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAskStories

func GetAskStories() ([]int, error)

GetAskStories retrieves ask story ids.

func GetBestStories

func GetBestStories() ([]int, error)

GetBestStories retrieves best story ids.

func GetJobStories

func GetJobStories() ([]int, error)

GetJobStories retrieves job story ids.

func GetLatestItemId

func GetLatestItemId() (int, error)

GetLatestItemId returns the current largest item id from the Hacker News API.

func GetNewStories

func GetNewStories() ([]int, error)

GetNewStories retrieves new story ids.

func GetShowStories

func GetShowStories() ([]int, error)

GetShowStories retrieves show story ids.

func GetStoryIds

func GetStoryIds(url string) ([]int, error)

GetStoryIds retrieves story ids from the given url.

func GetTopStories

func GetTopStories() ([]int, error)

GetTopStories retrieves top story ids.

func IterateItemsByBatch

func IterateItemsByBatch(batchSize int, cb func(batch []*Item) (bool, error)) error

IterateStoriesByBatch retrieves stories by batch of a specified limit.

Types

type FullStory

type FullStory struct {
	Story    *Item   `json:"story"`
	Comments []*Item `json:"comments"`
}

func FetchFullStory

func FetchFullStory(story *Item) (*FullStory, error)

type Item

type Item struct {
	ID          int      `json:"id"`                    // The item's unique id.
	Deleted     bool     `json:"deleted,omitempty"`     // true if the item is deleted.
	Type        ItemType `json:"type"`                  // The type of item. One of "job", "story", "comment", "poll", or "pollopt".
	By          string   `json:"by,omitempty"`          // The username of the item's author.
	Time        UnixTime `json:"time"`                  // Creation date of the item, in Unix Time.
	Text        string   `json:"text,omitempty"`        // The comment, story or poll text. HTML.
	Dead        bool     `json:"dead,omitempty"`        // true if the item is dead.
	Parent      int      `json:"parent,omitempty"`      // The comment's parent: either another comment or the relevant story.
	Poll        int      `json:"poll,omitempty"`        // The pollopt's associated poll.
	Kids        []int    `json:"kids,omitempty"`        // The ids of the item's comments, in ranked display order.
	URL         string   `json:"url,omitempty"`         // The URL of the story.
	Score       int      `json:"score,omitempty"`       // The story's score, or the votes for a pollopt.
	Title       string   `json:"title,omitempty"`       // The title of the story, poll or job. HTML.
	Parts       []int    `json:"parts,omitempty"`       // A list of related pollopts, in display order.
	Descendants int      `json:"descendants,omitempty"` // In the case of stories or polls, the total comment count.
}

func GetItem

func GetItem(id int) (*Item, error)

type ItemType

type ItemType string
const (
	JobType     ItemType = "job"
	StoryType   ItemType = "story"
	CommentType ItemType = "comment"
	PollType    ItemType = "poll"
	PollOptType ItemType = "pollopt"
)

type UnixTime

type UnixTime int64

func (UnixTime) Time

func (t UnixTime) Time() time.Time

Time converts UnixTime to time.Time format.

func (*UnixTime) UnmarshalJSON

func (t *UnixTime) UnmarshalJSON(b []byte) error

UnmarshalJSON converts a Unix timestamp to UnixTime during JSON unmarshaling.

type Updates

type Updates struct {
	Items    []int    `json:"items"`    // List of updated item IDs
	Profiles []string `json:"profiles"` // List of updated profile usernames
}

Updates represents the updated items and profiles.

func GetUpdates

func GetUpdates() (Updates, error)

GetUpdates retrieves the updates.

type User

type User struct {
	// The user's unique username. Case-sensitive.
	Id string `json:"id"`
	// Creation date of the user, in Unix Time.
	Created int64 `json:"created"`
	// The user's karma.
	Karma int `json:"karma"`
	// The user's optional self-description. HTML.
	About string `json:"about"`
	// List of the user's stories, polls and comments.
	Submitted []int `json:"submitted"`
}

func GetUser

func GetUser(userId string) (*User, error)

Jump to

Keyboard shortcuts

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