sourcehut

package module
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: 4 Imported by: 1

README

Sourcehut Go SDK

Issue Tracker Patches GoDoc

This is the repository for the unofficial Sourcehut Go SDK.

Submitting Patches

To submit a patch, first read the mailing list etiquette and contribution guides and then send patches to the terraform-provider-sourcehut mailing list. Please prefix the subject with [PATCH sourcehut-go]. To configure your checkout of this repo to always use the correct prefix and send to the correct list cd into the repo and run:

git config sendemail.to ~samwhited/terraform-provider-sourcehut@lists.sr.ht
git config format.subjectPrefix 'PATCH sourcehut-go'

Documentation

Overview

Package sourcehut provides access to the Sourcehut HTTP API.

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 like http.Client except that it knows how to authenticate to the Sourcehut API.

func NewBaseClient

func NewBaseClient(base *http.Client) Client

NewBaseClient returns a new Sourcehut API client configured to use the provided http.Client to perform HTTP requests.

To add authentication use NewClient or provide a base client that is authenticated with the Sourcehut API.

func NewClient

func NewClient(opts ...Option) Client

NewClient returns a new Sourcehut API client configured with the provided options.

func (Client) Do

func (c Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response. The response is unmarshaled into v if successful, or returned as an error value if an API error has occured.

func (Client) List

func (c Client) List(req *http.Request, d func() interface{}) *Iter

List returns an iterator that can transparently make API requests to a paginated endpoint. Each item will be decoded into the value returned from a call to d. If d is nil, a map[string]interface{} is created for each item.

No HTTP request will be issued until iteration is started by a call to Next.

type Error

type Error struct {
	Field  string
	Reason string
	// contains filtered or unexported fields
}

Error represents an individual error returned from a Sourcehut API call.

API docs: https://man.sr.ht/api-conventions.md#error-responses

func (Error) Error

func (err Error) Error() string

Error satisfies the error interface for Error.

func (Error) StatusCode added in v0.0.3

func (err Error) StatusCode() int

StatusCode returns the HTTP status code of the request that unmarshaled this error. May not be set for Errors originating from code outside this package.

type Errors

type Errors []Error

Errors is a slice of Error's that itself implements error.

func (Errors) Error

func (err Errors) Error() string

Error satisfies the error interface for Errors.

func (Errors) StatusCode added in v0.0.3

func (err Errors) StatusCode() int

StatusCode returns the HTTP status code of the request that unmarshaled this error. May not be set for Errors originating from code outside this package.

type Iter

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

Iter provides a convenient API for iterating over the elements returned from paginated list API calls. Successive calls to the Next method step through each item in the list, fetching pages as needed.

func (*Iter) Current

func (i *Iter) Current() interface{}

Current returns the most recent item visited by the iterator.

func (*Iter) Err

func (i *Iter) Err() error

Err returns the last error encountered by the iterator. It will only return a non-nil value if the previous call to Next returned false (but Next returning false does not guarantee that Err will return a non-nil value).

func (*Iter) Next

func (i *Iter) Next() bool

Next advances the iterator to the next item in the list and makes it available through the Current method. When the end of the list is reached it returns False.

type Option

type Option func(*Transport)

Option is used to configure a Sourcehut API client.

func RoundTripper

func RoundTripper(rt http.RoundTripper) Option

RoundTripper returns an option that configures the client to use the provided http.RoundTripper for HTTP requests. If unspecified, http.DefaultTransport is used.

func Token

func Token(t string) Option

Token returns an option that configures the client to use the provided access token when making API requests. If no token is provided, the client can only make requests that do not require authentication.

func UserAgent

func UserAgent(ua string) Option

UserAgent returns an option that configures the client to use the provided user agent when making API requests.

type Response

type Response struct {
	*http.Response `json:"-"`

	Next           string          `json:"next"`
	Results        json.RawMessage `json:"results"`
	ResultsPerPage int64           `json:"results_per_page"`
	Total          int64           `json:"total"`
}

Response is a Sourcehut API response. This wraps the standard http.Response and provides convenient access to pagination links.

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

type ShortUser

type ShortUser struct {
	CanonicalName string `json:"canonical_name"`
	Name          string `json:"name"`
}

ShortUser represents the unexpanded form of a user returned by most API endpoints.

type Transport

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

Transport is an http.RoundTripper wrapping a base RoundTripper and adding a Sourcehut API authorization header or user agent.

Transport is a low-level mechanism. Most code will use the NewClient method instead.

func NewTransport

func NewTransport(opts ...Option) *Transport

NewTransport returns an http.RoundTripper that is configured with the provided options.

func (*Transport) CancelRequest

func (t *Transport) CancelRequest(req *http.Request)

CancelRequest cancels an in-flight request by closing its connection.

If the underlying http.RoundTripper does not support cancelation, CancelRequest is a noop.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip authorizes and authenticates the request with an access token from Transport's Source.

type User added in v0.0.2

type User struct {
	ShortUser

	Email    string `json:"email"`
	URL      string `json:"url"`
	Location string `json:"location"`
	Bio      string `json:"bio"`
}

User represents the expanded form of a user.

Directories

Path Synopsis
cmd
srht Module
Package git provides easy API access to Sourcehut Git repositories.
Package git provides easy API access to Sourcehut Git repositories.
internal
testlog
Package testlog is a log.Logger that proxies to the Log function on a testing.T. It is used to group log messages under the tests that generated them in test output and to only show those messages if the test that generated them failed.
Package testlog is a log.Logger that proxies to the Log function on a testing.T. It is used to group log messages under the tests that generated them in test output and to only show those messages if the test that generated them failed.
Package lists provides easy API access to Sourcehut mailing lists.
Package lists provides easy API access to Sourcehut mailing lists.
Package meta provides easy API access to Sourcehut account info.
Package meta provides easy API access to Sourcehut account info.
Package paste provides easy API access to Sourcehut file pasting.
Package paste provides easy API access to Sourcehut file pasting.

Jump to

Keyboard shortcuts

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