xkcd

package
v0.0.0-...-c4986e2 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const INFO = "info.0.json"

INFO is xkcd API suffix for comic.

View Source
const URL = "http://xkcd.com"

URL is xkcd root URL.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	CheckedAt time.Time
	Comics    map[int]*Info
	LastNum   int
}

Cache represents cache of xkcd comics information.

func NewCache

func NewCache() *Cache

NewCache creates new pointer to Cache structure and initializes internal map.

func (*Cache) Dump

func (c *Cache) Dump(w io.Writer) error

Dump writes Cache marshaled as JSON to Writer.

func (*Cache) Load

func (c *Cache) Load(r io.Reader) error

Load reads cache represented as JSON from Reader and unmarshal them to Cache.

func (*Cache) Search

func (c *Cache) Search(arr []string) map[int]*Info

Search searches required strings within Cache and returns found comic Infos.

func (*Cache) Update

func (c *Cache) Update(all bool) error

Update gets the latest xkcd comic from site and compares with the latest from the Cache. If new comics are appeared they will be added to Cache. Parameter 'force' allowes to reinitialize cache from the begginging.

func (*Cache) UpdateOne

func (c *Cache) UpdateOne(num int) error

UpdateOne updates comic Info in Cache with given comic num (id).

type Info

type Info struct {
	Alt        string
	Day        string
	Image      string
	Link       string
	Month      string
	News       string
	Num        int
	SafeTitle  string `json:"safe_title"`
	Transcript string
	Year       string
	URL        string
}

Info represents xkcd comic information.

func FetchInfo

func FetchInfo(url string) (*Info, error)

FetchInfo gets xkcd comic information as json and unpack one to Info struct.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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