Back to godoc.org
git.sr.ht/~sircmpwn/sourcehut-go

Package srht

v0.0.0-...-5619ebe
Latest Go to latest

The latest major version is .

Published: Jan 9, 2020 | License: LGPL-3.0 | Module: git.sr.ht/~sircmpwn/sourcehut-go

Overview

The top-level srht module is used for shared code for the CLI programs. It's not generally useful to consumers of the Go API (except, perhaps, for SrhtConfig). Most applications will use the service-specific modules from their respective subdirectories (e.g. git.sr.ht/~sircmpwn/sourcehut-go/git.sr.ht).

Index

Constants

const (
	OP_ADD    = iota
	OP_GET    = iota
	OP_DELETE = iota
	OP_UPDATE = iota
	OP_HELP   = iota
)
const API_TIME_FORMAT = "2006-01-02T15:04:05-07:00"
const CLI_TIME_FORMAT = "Jan 2, 2006 15:04:05 UTC"

func NewCommandLine

func NewCommandLine(args []string) (*CommandLine, *SrhtConfig)

type CommandLine

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

func (*CommandLine) Run

func (cli *CommandLine) Run()

func (*CommandLine) RunEntry

func (cli *CommandLine) RunEntry(op int, ep *EntryPoint, args []string) error

func (*CommandLine) WithEntryPoint

func (cli *CommandLine) WithEntryPoint(entry ...*EntryPoint) *CommandLine

type Entry

type Entry func(args []string) error

type EntryOperation

type EntryOperation interface{}

type EntryOperationAdd

type EntryOperationAdd interface {
	EntryOperation
	Add(args []string) error
}

type EntryOperationDelete

type EntryOperationDelete interface {
	EntryOperation
	Delete(args []string) error
}

type EntryOperationGet

type EntryOperationGet interface {
	EntryOperation
	Get(args []string) error
}

type EntryOperationUpdate

type EntryOperationUpdate interface {
	EntryOperation
	Update(args []string) error
}

type EntryPoint

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

func NewEntryPoint

func NewEntryPoint(iface EntryOperation, path ...string) *EntryPoint

type SrhtClient

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

Generic container for a SourceHut API client.

func NewSrhtClient

func NewSrhtClient(token string, client *http.Client) *SrhtClient

Creates a new SourceHut client with the given OAuth token and http.Client.

func (*SrhtClient) Delete

func (c *SrhtClient) Delete(url string, out interface{}) error

Performs an authenticated DELETE request against a SourceHut service. The out parameter will be unmarshalled with the response.

func (*SrhtClient) Do

func (c *SrhtClient) Do(req *http.Request) (*http.Response, error)

Performs an authenticated HTTP request against a SourceHut service.

func (*SrhtClient) Get

func (c *SrhtClient) Get(url string, out interface{}) error

Performs an authenticated GET request against a SourceHut service. The out parameter will be unmarshalled with the response.

func (*SrhtClient) Post

func (c *SrhtClient) Post(url string,
	payload interface{}, out interface{}) error

Performs an authenticated POST request against a SourceHut service. The payload parameter will be marshalled as JSON and used as the request body. The out parameter will be unmarshalled with the response.

func (*SrhtClient) Put

func (c *SrhtClient) Put(url string,
	payload interface{}, out interface{}) error

Performs an authenticated PUT request against a SourceHut service.

type SrhtConfig

type SrhtConfig struct {
	Config              ini.File
	PersonalAccessToken string
}

func LoadConfig

func LoadConfig(path string) (*SrhtConfig, error)

"path" may be empty string to load from the default location.

func (*SrhtConfig) Get

func (conf *SrhtConfig) Get(section string, key string) (string, bool)

type SrhtError

type SrhtError struct {
	Field  *string `json:"field"`
	Reason string  `json:"reason"`
}

A validation error caused by an incorrectly formed API request.

type SrhtErrorResponse

type SrhtErrorResponse struct {
	StatusCode int
	Status     string
	Errors     []SrhtError `json:"errors"`
}

An error with the details of a failed API request.

func (SrhtErrorResponse) Error

func (r SrhtErrorResponse) Error() string

Formats information about a failed API request as a string.

type User

type User struct {
	Bio           *string `json:"bio"`
	CanonicalName string  `json:"canonical_name"`
	Email         string  `json:"email"`
	Location      *string `json:"location"`
	Name          string  `json:"name"`
	Url           *string `json:"url"`
}

Standard user info structure

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier