README
xkcd
xkcd
is a go library for accessing xkcd comics. This package also
comes with some example utilities.
License
See LICENSE.
Documentation
Overview ¶
Package xkcd allows access to metadata for xkcd comics.
Index ¶
Examples ¶
Constants ¶
Variables ¶
var ErrNotFound = errors.New("Error retrieving comic")
ErrNotFound is returned when the xkcd server returns a 4xx response code (like 404).
Functions ¶
Types ¶
type Comic ¶
type Comic struct { Num int `json:"num"` Title string `json:"title"` SafeTitle string `json:"safe_title"` Img string `json:"img"` Alt string `json:"alt"` Year string `json:"year"` Month string `json:"month"` Day string `json:"day"` News string `json:"news"` Link string `json:"link"` Transcript string `json:"transcript"` }
Comic is a struct that contains information about an xkcd comic.
func Get ¶
Get fetches information about the xkcd comic number `n'.
Example ¶
Output: Number: 140 Image: https://imgs.xkcd.com/comics/delicious.png Alt Text: I'm currently in the I Have Cheese phase of this cycle.
func GetCurrent ¶
GetCurrent fetches information for the newest xkcd comic.
func New ¶
New reads from an io.Reader and returns a *Comic struct. Assumes text is UTF-8. WARNING: this function will improperly decode comics retrieved directly from xkcd.com as xkcd.com provides ISO8859-1 encoded JSON instead of UTF-8 encoded JSON. Use Get or GetCurrent for retrieving comics directly from xkcd.com.
type Image ¶
Image represents an xkcd comic image.
func GetImage ¶
GetImage is a convenience function to download a comic's metadata and then download the comic's image. If you already have the comic metadata, use Comic's Image() method.
func (*Image) SourceFormat ¶
SourceFormat is the file format that the image was decoded from.
func (*Image) SourceName ¶
SourceName is the original file name of the comic image. If the Image wasn't retrieved from a URL (e.g. when it is created by calling NewImage directly), an empty string will be returned.
Directories
Path | Synopsis |
---|---|
cmd
|
|
xkcd-image
xkcd-image downloads an xkcd comic image to the current directory.
|
xkcd-image downloads an xkcd comic image to the current directory. |
xkcd-info
xkcd-info prints information about an xkcd comic.
|
xkcd-info prints information about an xkcd comic. |