paste

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: BSD-2-Clause Imports: 8 Imported by: 1

Documentation

Overview

Package paste provides easy API access to Sourcehut file pasting.

Index

Constants

View Source
const BaseURL = "https://paste.sr.ht/api/"

BaseURL is the default public Sourcehut paste API URL. It is exported for convenience.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blob

type Blob struct {
	ID       string    `json:"sha"`
	Created  time.Time `json:"created"`
	Contents string    `json:"contents"`
}

Blob contains data about an individual file in a paste.

type Client

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

Client handles communication with the paste related methods of the Sourcehut API.

API docs: https://man.sr.ht/paste.sr.ht/api.md

func NewClient

func NewClient(opts ...Option) (*Client, error)

NewClient returns a new paste API client.

func (*Client) Get

func (c *Client) Get(id string) (Paste, error)

Get returns information about a paste with the given ID.

func (*Client) GetBlob

func (c *Client) GetBlob(id string) (Blob, error)

GetBlob returns information about a particular file in a paste.

func (*Client) List

func (c *Client) List() (Iter, error)

List returns an iterator over all pastes owned by the authenticated user.

func (*Client) New

func (c *Client) New(f Files) (Paste, error)

New creates an new paste from the list of files.

func (*Client) Version

func (c *Client) Version() (string, error)

Version returns the version of the API.

API docs: https://man.sr.ht/api-conventions.md#get-apiversion

type Files

type Files []struct {
	Name     string `json:"filename"`
	Contents string `json:"contents"`
}

Files is a list of file names and their contents.

type Iter

type Iter struct {
	*sourcehut.Iter
}

Iter is used for iterating over a collection of pastes.

func (Iter) Paste

func (i Iter) Paste() *Paste

Paste returns the paste which the iterator is currently pointing to.

type Option

type Option func(*Client) error

Option is used to configure an API client.

func Base

func Base(base string) Option

Base returns an option that configures the public Sourcehut API URL.

If base does not have a trailing slash, one is added automatically. If unspecified, BaseURL is used.

func SrhtClient

func SrhtClient(client sourcehut.Client) Option

SrhtClient returns an option that configures the client to use the provided sourcehut.Client for API requests. If unspecified, the default sourcehut.Client (with no options of its own) is used.

type Paste

type Paste struct {
	ID      string              `json:"sha"`
	Created time.Time           `json:"created"`
	User    sourcehut.ShortUser `json:"user"`
	Files   []struct {
		ID   string `json:"blob_id"`
		Name string `json:"filename"`
	} `json:"files"`
}

Paste contains data about a set of files.

Jump to

Keyboard shortcuts

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