requests

package module
v0.0.0-...-f7bd8c3 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2023 License: MIT Imports: 12 Imported by: 1

README

request

Makes my life easier when making requests to 3rd party apis

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewReqAuditor

func NewReqAuditor(auditor Auditor, userID, action string) *reqAuditor

Types

type Auditor

type Auditor interface {
	// UserSuccess audits the requests and response when the http status
	// code is <300.
	UserSuccess(userID, action string, metadata map[string]interface{})
	// UserFail audits the requests and response when the http status
	// code is >=300.
	UserFail(userID, action string, metadata map[string]interface{})
}

type Authorization

type Authorization interface {
	// Authorize is called after everything is set to the http.Request
	// and before making the request, so everything needed to authorize
	// it is added.
	Authorize(req *http.Request) (*http.Request, error)
}

Authorization adds the authorization to the http.Request. It should change the http.Request to include whatever needs to be added.

type BearerAuthorization

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

BearerAuthorization authorizes http requests with a bearer token.

func NewBearerAuth

func NewBearerAuth(accessToken string) *BearerAuthorization

NewBearerAuth returns a new BearerAuthorization.

func (*BearerAuthorization) Authorize

func (a *BearerAuthorization) Authorize(req *http.Request) (*http.Request, error)

Authorize sets an Authorization header with the bearer token.

type Error

type Error struct {
	HttpStatusCode int    `json:"-"`
	Data           string `json:"-"`
}

Error handles the errors received from the provider.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

type Float

type Float float64

func (*Float) UnmarshalJSON

func (f *Float) UnmarshalJSON(data []byte) error

type Request

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

Request makes a new http Request with the params, headers and body set.

func NewRequest

func NewRequest(
	baseURL *url.URL,
	client *http.Client,
	accepts string,
) *Request

NewRequest returns a new request.

func (*Request) Delete

func (r *Request) Delete(ctx context.Context, path string) (interface{}, error)

func (*Request) Get

func (r *Request) Get(ctx context.Context, path string) (interface{}, error)

func (*Request) Post

func (r *Request) Post(ctx context.Context, path string) (interface{}, error)

func (*Request) Request

func (r *Request) Request(ctx context.Context, method, path string) (*http.Request, error)

func (*Request) WithAuditor

func (r *Request) WithAuditor(a RequestAuditor) *Request

func (*Request) WithAuthorization

func (r *Request) WithAuthorization(a Authorization) *Request

func (*Request) WithFormBody

func (r *Request) WithFormBody(vals url.Values) *Request

func (*Request) WithHeader

func (r *Request) WithHeader(key, value string) *Request

func (*Request) WithHeaders

func (r *Request) WithHeaders(headers url.Values) *Request

func (*Request) WithJSONBody

func (r *Request) WithJSONBody(obj interface{}) *Request

func (*Request) WithQParam

func (r *Request) WithQParam(key, value string) *Request

WithQParam adds a query parameter to the requests.

func (*Request) WithQParamPtr

func (r *Request) WithQParamPtr(key string, value *string) *Request

func (*Request) WithResult

func (r *Request) WithResult(result interface{}) *Request

type RequestAuditor

type RequestAuditor interface {
	// SetReq sets the HTTP request to the provider to be audited.
	SetReq(req *http.Request)
	// SetResp sets the HTTP response from the provider to be audited.
	SetResp(resp *http.Response)
	// Audit sends the audit trail to the Auditor.
	Audit()
}

RequestAuditor audits the http requests and corresponding response.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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