export

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrJSONMarshal reports an error marshaling JSON.
	ErrJSONMarshal = errors.New("export: error marshaling JSON")
	// ErrFileCreate reports an error creating a file.
	ErrFileCreate = errors.New("export: error creating file")
	// ErrFileWrite reports an error writing a file.
	ErrFileWrite = errors.New("export: error writing file")
	// ErrHTTPRequest reports an error generating a HTTP request.
	ErrHTTPRequest = errors.New("export: request error")
	// ErrHTTPConnection reports an error sending a HTTP request.
	ErrHTTPConnection = errors.New("export: HTTP connection error")
	// ErrHTTPResponse reports a HTTP response error, such as bad status code.
	ErrHTTPResponse = &HTTPResponseError{}
)

Functions

func HTTP

func HTTP(src HTTPRequester) error

HTTP sends the HTTP Request created by src and returns the first error occurring in the process. The error value can be:

  • ErrHTTPRequest if it fails to create or send the request
  • ErrHTTPResponse if the response returned a bad status code
  • nil otherwise.

func JSONFile

func JSONFile(filename string, src interface{}) error

JSONFile marshals src to JSON and write the result to a file with the given filename.

func Stdout

func Stdout(src fmt.Stringer)

Stdout writes src to os.Stdout.

Types

type HTTPRequester

type HTTPRequester interface {
	HTTPRequest() (*http.Request, error)
}

HTTPRequester interface expects a methods HTTPRequest returning a *http.Request to be sent in func HTTP.

type HTTPResponseError added in v1.0.0

type HTTPResponseError struct {
	Code int
}

HTTPResponseError is an HTTP error due to a bad response code. It contains the received HTTP status code.

func (*HTTPResponseError) Error added in v1.0.0

func (e *HTTPResponseError) Error() string

Error implements error.

func (*HTTPResponseError) Is added in v1.0.0

func (e *HTTPResponseError) Is(err error) bool

Is returns true if err's type is HTTPResponseError. It allows comparison with ErrHTTPResponse using errors.Is:

errors.Is(&HTTPResponseError{}, ErrHTTPResponse) // true
errors.Is(errors.New("any"), ErrHTTPResponse) // false

It does not perform check equality on the status code.

func (*HTTPResponseError) WithCode added in v1.0.0

func (e *HTTPResponseError) WithCode(code int) *HTTPResponseError

WithCode returns a *HTTPResponseError initialized with code.

type Interface

type Interface interface {
	fmt.Stringer
	HTTPRequester
}

Interface gathers the necessary methods to use any function exposed in this package.

Jump to

Keyboard shortcuts

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