Skip to content
Go
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE Initial Feb 26, 2016
README.md 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

README.md

go-xkcd

xkcd API client for Golang.

wercker status Coverage Status GoDoc

https://xkcd.com/1481/

Details on the xkcd API can be found here.

Install

$ go get github.com/nishanths/go-xkcd

Import the package using github.com/nishanths/go-xkcd and refer to it as xkcd.

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

Example

The following program prints details about xkcd.com/599:

package main

import (
    "fmt"
    "log"

    "github.com/nishanths/go-xkcd"
)

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

    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("%s: %s", comic.Title, comic.ImageURL) // Apocalypse: http://imgs.xkcd.com/comics/apocalypse.png
}

Test

To run tests:

$ go test

Documentation

View Go Doc online.

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

$ godoc -http=:6060

Then visit http://localhost:6060/pkg/github.com/nishanths/go-xkcd/ in your browser.

Methods

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
}

Contributing

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

License

The MIT License. Copyright © Nishanth Shanmugham.

You can’t perform that action at this time.