fetch

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendQueryParams

func AppendQueryParams(rawUrl string, queryParams map[string]string) (string, error)

func Fetch

func Fetch(rawUrl string, options FetchOptions) (*http.Response, error)

Fetch simplifies common http requests and associated error checking

func FetchFile

func FetchFile(raw_url string, options FetchOptions, directory, filename string) (string, error)

FetchFile simplifies the common task of downloading a file from a url, returning the file's location if filename does not contain an extension, an attempt will be made to infer it from the request's Content-Type header

func FetchJson

func FetchJson[OUTPUT_TYPE any](rawUrl string, options FetchOptions) (OUTPUT_TYPE, error)

FetchJson simplifies the common task of making a HTTP request to fetch some JSON data and returning it as a struct

func FetchString

func FetchString(rawUrl string, options FetchOptions) (string, error)

FetchString simplifies the common task of making a HTTP request to fetch some plaintext data

func IsBadResponseWithCode

func IsBadResponseWithCode(err error, code int) bool

a helper function to simplify checking HTTP status codes from potentially-wrapped errors

func JsonToReader

func JsonToReader(input any) io.Reader

JsonToReader simplifies marshalling a struct to json for use in http requests (which accept io.Reader instead of []byte)

func LogPossibleFetchError

func LogPossibleFetchError(err error) bool

func LogResponseDetails

func LogResponseDetails(response *http.Response)

func ReadJson

func ReadJson[OUTPUT_TYPE any](r io.Reader) (OUTPUT_TYPE, error)

func ReadJsonString

func ReadJsonString[OUTPUT_TYPE any](input string) (OUTPUT_TYPE, error)

func ReadString

func ReadString(r io.Reader) (string, error)

func ResponseOk

func ResponseOk(response *http.Response) (bool, error)

Types

type BadResponseError

type BadResponseError struct {
	StatusCode int
}

func (BadResponseError) Error

func (e BadResponseError) Error() string

type FetchError

type FetchError struct {
	Response *http.Response
	Err      error
}

func (FetchError) Error

func (e FetchError) Error() string

func (FetchError) Unwrap

func (e FetchError) Unwrap() error

type FetchOptions

type FetchOptions struct {
	Method            string
	Query             map[string]string
	Headers           map[string]string
	Body              io.Reader
	Timeout           *time.Duration
	Logging           bool
	AcceptBadResponse bool
}

Jump to

Keyboard shortcuts

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