Skip to content
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE Initial Feb 26, 2016 Fix comments Mar 1, 2016
client.go Simplify request logic in client May 31, 2016
client_test.go Use https in tests Feb 26, 2016
comics.go Fix comments Mar 1, 2016
comics_test.go Update error name Feb 26, 2016
config.go Add docs Feb 26, 2016
doc.go Edit docs Feb 27, 2016
errors.go Finish remaining docs Feb 26, 2016
random.go Shorten function names Feb 26, 2016
wercker.yml Setup build and test coverage Feb 26, 2016


xkcd API client for Golang.

wercker status Coverage Status GoDoc

Details on the xkcd API can be found here.


$ go get

Import the package using and refer to it as xkcd.

Each major version has a separate branch. If you need a specific version, please clone the branch instead.


The following program prints details about

package main

import (


func main() {
    client := xkcd.NewClient()
    comic, err := client.Get(599)

    if err != nil {

    fmt.Printf("%s: %s", comic.Title, comic.ImageURL) // Apocalypse:


To run tests:

$ go test


View Go Doc online.

To view go docs locally, after installing the package run:

$ godoc -http=:6060

Then visit http://localhost:6060/pkg/ in your browser.


The following methods are available on the client. All the methods return (Comic, error).

  • Latest()
  • Get(number int)
  • Random()
  • RandomInRange(begin, end, latest int)

The fields available on Comic are:

type Comic struct {
	Alt         string
	PublishDate time.Time
	ImageURL    string
	URL         string
	News        string
	Number      int
	SafeTitle   string
	Title       string
	Transcript  string


Pull requests and issues are welcome!

To create a new pull request:

  1. Fork the repository
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request on GitHub


The MIT License. Copyright © Nishanth Shanmugham.

You can’t perform that action at this time.