srht

package module
v0.0.0-...-5619ebe Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: LGPL-3.0 Imports: 11 Imported by: 0

README

sourcehut-go

sourcehut-go is a set of Go libraries and command line utilities for interacting with SourceHut via the API.

Note: this is a work in progress.

Configuration

sourcehut-go looks for a configuration file at ~/.config/sourcehut.conf (or the XDG basedir-appropriate location). The simplest configuration is:

personal-access-token=...

You can generate a personal access token in your meta.sr.ht OAuth settings. The file can also be used to specify which upstream instance of sr.ht you want to talk to for each service:

personal-access-token=...

[meta.sr.ht]
origin=https://meta.sr.ht

[git.sr.ht]
origin=https://git.example.org

If you just use the canonical sr.ht instance for everything, then you don't need to configure this.

Documentation

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

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

Variables

This section is empty.

Functions

func NewCommandLine

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

Types

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

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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