yank

package
v0.0.131 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package yank provides HTTP Client functions

Index

Constants

View Source
const (
	AuthTypeNone = iota
	AuthTypeBasic
	AuthTypeToken
	AuthTypeBearerToken
	AuthTypeCookieWithCSRFToken
	AuthTypeEDS
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplyDefaultsError

type ApplyDefaultsError struct {
	Parent error
}

ApplyDefaultsError - Ошибка применения настроек по умолчанию (1) -----------------------------------------------------------------

func (*ApplyDefaultsError) Error

func (e *ApplyDefaultsError) Error() string

type Auth

type Auth interface {
	HTTPHeaders
}

func NewAuthBasic

func NewAuthBasic(username, password string) Auth

func NewAuthBearerToken

func NewAuthBearerToken(token string) Auth

func NewAuthCookieWithCSRFToken

func NewAuthCookieWithCSRFToken(cookie, token string) Auth

func NewAuthEDS

func NewAuthEDS(keyID, body string) Auth

func NewAuthNone

func NewAuthNone() Auth

func NewAuthToken

func NewAuthToken(token string) Auth

type AuthBasic

type AuthBasic struct {
	BaseAuth

	Username string
	Password string
}

func (*AuthBasic) AddHeaders

func (a *AuthBasic) AddHeaders(r *HTTPRequest)

type AuthBearerToken

type AuthBearerToken struct {
	BaseAuth

	Token string
}

func (*AuthBearerToken) AddHeaders

func (a *AuthBearerToken) AddHeaders(r *HTTPRequest)

type AuthConstructor

type AuthConstructor interface {
	AuthNone()
	AuthBasic(username, password string)
	AuthToken(token string)
	AuthBearerToken(token string)
	AuthCookieWithCSRFToken(cookie, token string)
	AuthEDS(keyID, body string)
}

type AuthCookieWithCSRFToken

type AuthCookieWithCSRFToken struct {
	BaseAuth

	Cookie string
	Token  string
}

func (*AuthCookieWithCSRFToken) AddHeaders

func (a *AuthCookieWithCSRFToken) AddHeaders(r *HTTPRequest)

type AuthEDS

type AuthEDS struct {
	BaseAuth

	SignKeyID string
	SignBody  string
}

func (*AuthEDS) AddHeaders

func (a *AuthEDS) AddHeaders(r *HTTPRequest)

type AuthNone

type AuthNone struct {
	BaseAuth
}

func (*AuthNone) AddHeaders

func (a *AuthNone) AddHeaders(r *HTTPRequest)

type AuthToken

type AuthToken struct {
	BaseAuth

	Token string
}

func (*AuthToken) AddHeaders

func (a *AuthToken) AddHeaders(r *HTTPRequest)

type BaseAuth

type BaseAuth struct {
	AuthType int
}

type BaseContent

type BaseContent struct {
	MimeType string
	Data     interface{}
}

type BodyBuffer

type BodyBuffer struct {
	*bytes.Buffer
}

func (*BodyBuffer) Len

func (buffer *BodyBuffer) Len() int

func (*BodyBuffer) String

func (buffer *BodyBuffer) String() string

type BodyConstructor

type BodyConstructor interface {
	SetBody(content Content)
}

type BytesData added in v0.0.125

type BytesData struct {
	BaseContent
}

func (*BytesData) GetRawContent added in v0.0.125

func (d *BytesData) GetRawContent() (raw *RawContent, err error)

type Client

type Client struct {
	Defaults *Defaults
}

func (*Client) ApplyDefaultsOnRequest

func (c *Client) ApplyDefaultsOnRequest(request *Request, ignoreDefaults bool) error

func (*Client) DELETE

func (c *Client) DELETE(request *Request, response *Response, ignoreDefaults bool) error

func (*Client) GET

func (c *Client) GET(request *Request, response *Response, ignoreDefaults bool) error

func (*Client) GetDefaults added in v0.0.109

func (c *Client) GetDefaults() *Defaults

func (*Client) Light added in v0.0.106

func (c *Client) Light() LightService

func (*Client) PATCH

func (c *Client) PATCH(request *Request, response *Response, ignoreDefaults bool) error

func (*Client) POST

func (c *Client) POST(request *Request, response *Response, ignoreDefaults bool) error

func (*Client) PUT

func (c *Client) PUT(request *Request, response *Response, ignoreDefaults bool) error

func (*Client) Request

func (c *Client) Request(request *Request, response *Response, ignoreDefaults bool) (err error)

Request - make http request

type Content

type Content interface {
	GetRawContent() (raw *RawContent, err error)
}

func NewBytes added in v0.0.125

func NewBytes(data interface{}, mimeType string) Content

func NewFormMultipart

func NewFormMultipart(data interface{}) Content

func NewFormURLEncoded

func NewFormURLEncoded(data interface{}) Content

func NewJSON

func NewJSON(data interface{}) Content

type CreateHTTPRequestError

type CreateHTTPRequestError struct {
	Method         string
	URL            string
	MimeType       string
	RequestRawBody string
	Parent         error
}

CreateHTTPRequestError - Ошибка создания http запроса (3) ----------------------------------------------------------

func (*CreateHTTPRequestError) Error

func (e *CreateHTTPRequestError) Error() string

type Defaults

type Defaults struct {
	URL             string
	Auth            Auth
	Headers         http.Header
	FollowRedirects bool
	Transport       http.RoundTripper
}

func NewDefaults

func NewDefaults(url string) *Defaults

func (*Defaults) AddHeader

func (d *Defaults) AddHeader(key, value string)

func (*Defaults) AddHeaders

func (d *Defaults) AddHeaders(r *HTTPRequest)

func (*Defaults) AuthBasic

func (d *Defaults) AuthBasic(username, password string)

func (*Defaults) AuthBearerToken

func (d *Defaults) AuthBearerToken(token string)

func (*Defaults) AuthConstructor

func (d *Defaults) AuthConstructor() AuthConstructor

func (*Defaults) AuthCookieWithCSRFToken

func (d *Defaults) AuthCookieWithCSRFToken(cookie, token string)

func (*Defaults) AuthEDS

func (d *Defaults) AuthEDS(keyID, body string)

func (*Defaults) AuthNone

func (d *Defaults) AuthNone()

func (*Defaults) AuthToken

func (d *Defaults) AuthToken(token string)

func (*Defaults) HeaderConstructor

func (d *Defaults) HeaderConstructor() HeaderConstructor

func (*Defaults) SetFollowRedirects added in v0.0.123

func (d *Defaults) SetFollowRedirects(value bool)

func (*Defaults) SetTransport added in v0.0.123

func (d *Defaults) SetTransport(value http.RoundTripper)

type DefaultsConstructor

type DefaultsConstructor interface {
	HeaderConstructor
	AuthConstructor
}

type ExecuteHTTPRequestError

type ExecuteHTTPRequestError struct {
	Method            string
	URL               string
	MimeType          string
	RequestRawBody    string
	RequestRawHeaders http.Header
	Parent            error
}

ExecuteHTTPRequestError - Ошибка исполнения http запроса (4) -------------------------------------------------------------

func (*ExecuteHTTPRequestError) Error

func (e *ExecuteHTTPRequestError) Error() string

type FormMultipartData

type FormMultipartData struct {
	BaseContent
}

func (*FormMultipartData) GetRawContent

func (d *FormMultipartData) GetRawContent() (raw *RawContent, err error)

type FormURLEncodedData

type FormURLEncodedData struct {
	BaseContent
}

func (*FormURLEncodedData) GetRawContent

func (d *FormURLEncodedData) GetRawContent() (raw *RawContent, err error)

type HTTPHeaders

type HTTPHeaders interface {
	AddHeaders(r *HTTPRequest)
}

type HTTPRequest

type HTTPRequest struct {
	*http.Request
	FollowRedirects bool
	Transport       http.RoundTripper
}

func (*HTTPRequest) AddHeaders

func (r *HTTPRequest) AddHeaders(headers http.Header)

func (*HTTPRequest) Execute

func (r *HTTPRequest) Execute() (httpResponse *HTTPResponse, err error)

type HTTPResponse

type HTTPResponse struct {
	*http.Response
	Timer *tracktime.Tracker

	RawBody []byte
}

func (*HTTPResponse) Parse

func (rs *HTTPResponse) Parse(data interface{}) error

func (*HTTPResponse) ReadBody

func (rs *HTTPResponse) ReadBody() error

type HeaderConstructor

type HeaderConstructor interface {
	AddHeader(key, value string)
}

type JSONData

type JSONData struct {
	BaseContent
}

func (*JSONData) GetRawContent

func (d *JSONData) GetRawContent() (raw *RawContent, err error)

type LightClient added in v0.0.106

type LightClient struct {
	*Client
}

func (*LightClient) DELETE added in v0.0.106

func (lc *LightClient) DELETE(
	route string,
	send interface{},
	receiver interface{},
	expectedStatusCode int,
	mimeType string,
) (statusCode int, rawBody []byte, err error)

func (*LightClient) GET added in v0.0.106

func (lc *LightClient) GET(
	route string,
	receiver interface{},
	expectedStatusCode int,
) (statusCode int, rawBody []byte, err error)

func (*LightClient) PATCH added in v0.0.106

func (lc *LightClient) PATCH(
	route string,
	send interface{},
	receiver interface{},
	expectedStatusCode int,
	mimeType string,
) (statusCode int, rawBody []byte, err error)

func (*LightClient) POST added in v0.0.106

func (lc *LightClient) POST(
	route string,
	send interface{},
	receiver interface{},
	expectedStatusCode int,
	mimeType string,
) (statusCode int, rawBody []byte, err error)

func (*LightClient) PUT added in v0.0.106

func (lc *LightClient) PUT(
	route string,
	send interface{},
	receiver interface{},
	expectedStatusCode int,
	mimeType string,
) (statusCode int, rawBody []byte, err error)

func (*LightClient) Request added in v0.0.106

func (lc *LightClient) Request(
	method,
	route string,
	send interface{},
	receiver interface{},
	expectedStatusCode int,
	mimeType string,
) (int, []byte, error)

type LightService added in v0.0.106

type LightService interface {
	Request(
		method,
		route string,
		send interface{},
		receiver interface{},
		expectedStatusCode int,
		mimeType string,
	) (statusCode int, rawBody []byte, err error)

	GET(
		route string,
		receiver interface{},
		expectedStatusCode int,
	) (statusCode int, rawBody []byte, err error)

	POST(
		route string,
		send interface{},
		receiver interface{},
		expectedStatusCode int,
		mimeType string,
	) (statusCode int, rawBody []byte, err error)

	PUT(
		route string,
		send interface{},
		receiver interface{},
		expectedStatusCode int,
		mimeType string,
	) (statusCode int, rawBody []byte, err error)

	PATCH(
		route string,
		send interface{},
		receiver interface{},
		expectedStatusCode int,
		mimeType string,
	) (statusCode int, rawBody []byte, err error)

	DELETE(
		route string,
		send interface{},
		receiver interface{},
		expectedStatusCode int,
		mimeType string,
	) (statusCode int, rawBody []byte, err error)
}

type ParseResponseError

type ParseResponseError struct {
	Method             string
	URL                string
	MimeType           string
	RequestRawBody     string
	RequestRawHeaders  http.Header
	ResponseRawBody    string
	ResponseRawHeaders http.Header
	Parent             error
}

ParseResponseError - Ошибка разбора тела ответа в структуру (7) ----------------------------------------------------------------

func (*ParseResponseError) Error

func (e *ParseResponseError) Error() string

type QueryConstructor

type QueryConstructor interface {
	AddQuery(key, value string)
}

type RawContent

type RawContent struct {
	Body          string
	MimeType      string
	ContentType   string
	ContentLength int
	// contains filtered or unexported fields
}

func NewRawContent

func NewRawContent(buffer *bytes.Buffer, mimeType string, contentType string) *RawContent

func (*RawContent) AddHeaders

func (rc *RawContent) AddHeaders(r *HTTPRequest)

func (*RawContent) GetBuffer

func (rc *RawContent) GetBuffer() io.Reader

type RawContentError

type RawContentError struct {
	Method   string
	URL      string
	MimeType string
	Parent   error
}

RawContentError - Ошибка формирования тела запроса из структуры данных (2) ---------------------------------------------------------------------------

func (*RawContentError) Error

func (e *RawContentError) Error() string

type ReadBodyHTTPRequestError

type ReadBodyHTTPRequestError struct {
	Method             string
	URL                string
	MimeType           string
	RequestRawBody     string
	RequestRawHeaders  http.Header
	ResponseRawHeaders http.Header
	Parent             error
}

ReadBodyHTTPRequestError - Ошибка чтения тела http ответа (5) --------------------------------------------------------------

func (*ReadBodyHTTPRequestError) Error

func (e *ReadBodyHTTPRequestError) Error() string

type Request

type Request struct {
	Method          string
	URL             string
	Route           string
	Query           url.Values
	Auth            Auth
	Headers         http.Header
	Content         Content
	FollowRedirects bool
	Transport       http.RoundTripper
}

func NewRequest

func NewRequest(route string) *Request

func (*Request) AddHeader

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

func (*Request) AddQuery

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

func (*Request) AuthBasic

func (r *Request) AuthBasic(username, password string)

func (*Request) AuthBearerToken

func (r *Request) AuthBearerToken(token string)

func (*Request) AuthConstructor

func (r *Request) AuthConstructor() AuthConstructor

func (*Request) AuthCookieWithCSRFToken

func (r *Request) AuthCookieWithCSRFToken(cookie, token string)

func (*Request) AuthEDS

func (r *Request) AuthEDS(keyID, body string)

func (*Request) AuthNone

func (r *Request) AuthNone()

func (*Request) AuthToken

func (r *Request) AuthToken(token string)

func (*Request) BodyConstructor

func (r *Request) BodyConstructor() BodyConstructor

func (*Request) GetRawContent

func (r *Request) GetRawContent() (raw *RawContent, err error)

func (*Request) GetURI

func (r *Request) GetURI() string

func (*Request) HeaderConstructor

func (r *Request) HeaderConstructor() HeaderConstructor

func (*Request) NewHTTPRequest

func (r *Request) NewHTTPRequest(
	uri string,
	raw *RawContent,
	defaults *Defaults,
	ignoreDefaults bool,
) (httpRequest *HTTPRequest, err error)

func (*Request) QueryConstructor

func (r *Request) QueryConstructor() QueryConstructor

func (*Request) RequestConstructor

func (r *Request) RequestConstructor() RequestConstructor

func (*Request) SetBody

func (r *Request) SetBody(content Content)

func (*Request) SetFollowRedirects added in v0.0.120

func (r *Request) SetFollowRedirects(followRedirects bool)

func (*Request) SetTransport added in v0.0.121

func (r *Request) SetTransport(transport http.RoundTripper)

func (*Request) SetURL

func (r *Request) SetURL(url string)

func (*Request) URLConstructor

func (r *Request) URLConstructor() URLConstructor

type Response

type Response struct {
	ExpectedHTTPCode int

	HTTPCode int
	Headers  http.Header
	Raw      []byte
	Data     interface{}
	Timer    *tracktime.Tracker
}

func NewResponse

func NewResponse(data interface{}, expectedHTTPCode int) *Response

type Service

type Service interface {
	Request(request *Request, response *Response, ignoreDefaults bool) error
	GET(request *Request, response *Response, ignoreDefaults bool) error
	POST(request *Request, response *Response, ignoreDefaults bool) error
	PUT(request *Request, response *Response, ignoreDefaults bool) error
	PATCH(request *Request, response *Response, ignoreDefaults bool) error
	DELETE(request *Request, response *Response, ignoreDefaults bool) error
	Light() LightService
	GetDefaults() *Defaults
}

func New

func New(d *Defaults) Service

type URLConstructor

type URLConstructor interface {
	SetURL(url string)
}

type WrongHTTPCodeError

type WrongHTTPCodeError struct {
	Method             string
	URL                string
	MimeType           string
	RequestRawBody     string
	RequestRawHeaders  http.Header
	ResponseRawBody    string
	ResponseRawHeaders http.Header
	Expected           int
	Actual             int
}

WrongHTTPCodeError - Ошибка неверный http код (6) --------------------------------------------------

func (*WrongHTTPCodeError) Error

func (e *WrongHTTPCodeError) Error() string

Jump to

Keyboard shortcuts

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