cli

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisplayPostImage

func DisplayPostImage(
	ctx context.Context,
	out io.Writer,
	post *xkcd.Post,
	d Displayer,
) error

DisplayPost displays a post image.

func DisplayPostInfos

func DisplayPostInfos(out io.Writer, post *xkcd.Post, jsonMode bool) error

DisplayPostInfos displays the infos of a post.

Types

type Displayer

type Displayer func(io.Writer, image.Image) error

Displayer is a function that writes an image to an output writer.

func GetDisplayer

func GetDisplayer(logger *slog.Logger) Displayer

GetDisplayer checks if the terminal supports one of image inline protocols and returns the corresponding displayer or nil if it cannot.

type Execer

type Execer interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

Execer is an interface for the database's ExecContext method.

type Index

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

Index is an index instance.

func NewIndex

func NewIndex(path string, logger *slog.Logger) (*Index, error)

NewIndex creates a new index instance.

func (*Index) Close

func (i *Index) Close() error

Close closes the index.

func (*Index) Get

func (i *Index) Get(ctx context.Context, client *xkcd.Client, num uint) (*xkcd.Post, error)

Get gets a post. If it exists in index, it returns it. Else, it fetches it from xkcd API client and stores it in index.

func (*Index) GetLastUpdate

func (i *Index) GetLastUpdate() (time.Time, uint, error)

GetLastUpdate retrieves the last update date and post number from the index.

func (*Index) Init

func (i *Index) Init(ctx context.Context, force, offline bool) error

Init initializes the index.

func (*Index) Initized

func (i *Index) Initized() bool

Initialized returns true if the index is initialized.

func (*Index) Update

func (i *Index) Update(ctx context.Context, client *xkcd.Client, start, end, workers uint) error

Update updates the index with posts in range [start..end], with workers concurrent workers.

Jump to

Keyboard shortcuts

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