Documentation ¶
Index ¶
- Constants
- func RequestWithResponse[T any](r *Request) (response T, httpResponse *http.Response, err error)
- type Auth
- type Option
- func WithAuthorization(kind, value string) Option
- func WithBasicAuth(username, password string) Option
- func WithClient(client *http.Client) Option
- func WithHeaders(headers map[string]string) Option
- func WithPostHook(postHook func(*http.Response) error) Option
- func WithPreHook(preHook func(*http.Request) error) Option
- type Request
- func (r *Request) Do() (*http.Response, error)
- func (r *Request) WithBody(body io.Reader) *Request
- func (r *Request) WithContext(ctx context.Context) *Request
- func (r *Request) WithExtraHeaders(headers map[string]string) *Request
- func (r *Request) WithJsonBody(body interface{}) *Request
- func (r *Request) WithPostHook(hook func(req *http.Response) error) *Request
- func (r *Request) WithPreHook(hook func(req *http.Request) error) *Request
- type Session
Constants ¶
const ( AuthorizationHeader = "Authorization" AuthToken = "Token" AuthBearer = "Bearer" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Auth ¶
type Auth interface {
AddAuth(r *http.Request) error // this adds authentication to the requested request object
}
Auth represent different kinds of authentication.
type Option ¶
type Option interface {
SetOption(session *Session) // sets an option
}
Option defines an Option to the session object
func WithAuthorization ¶
WithAuthorization adds "Authorization: kind value" to the request
func WithBasicAuth ¶
WithBasicAuth returns an option that uses strict username and password
func WithClient ¶
func WithHeaders ¶
func WithPostHook ¶
WithPostHook adds a hook that is called just after we got the response
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request represents a request against the server
func (*Request) WithContext ¶
WithContext adds a context to the request.
func (*Request) WithExtraHeaders ¶
WithExtraHeaders adds extra headers to this request. They are added after the headers from the session object.
func (*Request) WithJsonBody ¶
WithJsonBody tries to JSON marshal the body and add it to the request. If it fails, an error is printed to the console.
func (*Request) WithPostHook ¶
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func NewSession ¶
NewSession creates a new session object
func (*Session) NewRequest ¶
NewRequest creates a new request object to perform a request on