xkcd

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2021 License: MIT Imports: 4 Imported by: 0

README

XKCD

An XKCD API and CLI.

You can find the API information on the about page near the bottom.

Library

package main

import (
	"context"
	
	"gitea.com/jolheiser/xkcd"
)

func main() {
	client := xkcd.New()
	comic, err := client.Current(context.Background())
	if err != nil {
		panic(err)
	}
	
	// Do stuff...
}

CLI

Build the CLI if you think it's useful.

If no comic number is given, it grabs the current comic.

./xkcd [--image] [--out=<path>] [<comic>]

  • --image - Get the image from the returned image URL. Pipe it wherever you want, or...
  • --out <path> - A path to a file to store the response (or image)

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an XKCD client

func New

func New(opts ...ClientOption) *Client

New returns a new XKCD Client

func (*Client) Comic

func (c *Client) Comic(ctx context.Context, num int) (*Comic, error)

Comic gets a specific XKCD Comic

func (*Client) Current

func (c *Client) Current(ctx context.Context) (*Comic, error)

Current gets the current XKCD Comic

type ClientOption

type ClientOption func(*Client)

ClientOption is options for a Client

func WithHTTP

func WithHTTP(client *http.Client) ClientOption

WithHTTP sets the http.Client for the XKCD Client

type Comic

type Comic struct {
	Month      string `json:"month"`
	Num        int    `json:"num"`
	Link       string `json:"link"`
	Year       string `json:"year"`
	News       string `json:"news"`
	SafeTitle  string `json:"safe_title"`
	Transcript string `json:"transcript"`
	Alt        string `json:"alt"`
	Img        string `json:"img"`
	Title      string `json:"title"`
	Day        string `json:"day"`
}

Comic is an XKCD comic

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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