Documentation
¶
Overview ¶
Package xkcd is a simple wrapper around xkcd's JSON interface.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FetchComicImg ¶
FetchComicImg is a utility function to download a comic image and store it locally on disk.
func FetchRandomComicNum ¶
FetchRandomComicNum gets a random comic number form the xkcd API.
Types ¶
type Comic ¶
type Comic struct { /* * Num is the comic number. * Day is the day the comic was published. * Month is the month the comic was published. * Year is the year the comic was published. * Title is the comic title. * SafeTitle is the same as Title (but safer?) ¯\_(ツ)_/¯. * Transcript is the textual description of the comic * Alt is the text content you seen when you hover over the comic image. * Img is the URL to the comic image. * News is for announcements (not sure, it's usually empty). * DateTime is the Day, Month and Year parsed into type Time. */ Num int `json:"num"` Day string `json:"day"` Month string `json:"month"` Year string `json:"year"` Title string `json:"title"` SafeTitle string `json:"safe_title"` Transcript string `json:"transcript"` Alt string `json:"alt"` Img string `json:"img"` News string `json:"news"` DateTime time.Time }
Comic is the parsed version of the JSON returned by the xkcd API.
func FetchComic ¶
FetchComic makes a request to the xkcd HTTP API, parses the JSON response into a Comic and returns it.
Example ¶
comic, err := FetchComic(1024) if err != nil { fmt.Printf("%s", err) } fmt.Printf( "[%s/%s/%s]: \"%s\"\n%s\n", comic.Month, comic.Day, comic.Year, comic.Title, comic.Img, )
Output: [3/2/2012]: "Error Code" https://imgs.xkcd.com/comics/error_code.png
func FetchRandomComic ¶
FetchRandomComic fetches a random comic number and fetches the Comic for that number.
func ParseComicResponse ¶
ParseComicResponse parses the JSON body of the HTTP response made to the xkcd API, and returns a Comic.
Click to show internal directories.
Click to hide internal directories.