client

package
v3.4.2 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoRequest  = "no request has been set"                  // Error message for when no request has been set
	ErrNoCallback = "no callback has been set"                 // Error message for when no callback has been set
	ErrNoEncoding = "no encoding has been set or is not valid" // Error message for when no encoding has been set
)

Define standard error messages

Functions

func Recover

func Recover(f func(err error)) any

Recover from a panic and print the stack trace

Types

type Client

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

Client is a client that can be used to execute http requests. - Can be used to execute GET, POST, PUT, DELETE, PATCH requests.

func NewClient

func NewClient() *Client

Client is a client that can be used to make requests to a server.

func (*Client) Do

func (c *Client) Do() (*http.Response, error)

Execute the request -> APIClient.exec

func (*Client) OnRecover

func (c *Client) OnRecover(f func(err error)) *Client

Do not reccover when an error occurs

func (*Client) Request

func (c *Client) Request(r *http.Request) *Client

Initialize a GET request

func (*Client) WithCookie

func (c *Client) WithCookie(cookie *http.Cookie) error

Add a HTTP.Cookie to the request

func (*Client) WithData

func (c *Client) WithData(formData map[string]string, encoding Encoding, file ...File) error

Add form data to the request

func (*Client) WithHeaders

func (c *Client) WithHeaders(headers map[string]string) error

Add headers to the request

func (*Client) WithQuery

func (c *Client) WithQuery(query map[string]string) error

Make a request with url query parameters

type Encoding

type Encoding string
const (
	FORM_URL_ENCODED Encoding = "application/x-www-form-urlencoded" // FORM_URL_ENCODED encoding
	MULTIPART_FORM   Encoding = "multipart/form-data"               // MULTIPART_FORM encoding
	JSON             Encoding = "json"                              // JSON encoding
	XML              Encoding = "xml"                               // XML encoding
)

Define methods of encoding

type File

type File struct {
	FileName  string    // Name of the file
	FieldName string    // Name of the field
	Reader    io.Reader // Reader of the file
}

Define a type for multipart files

type Methods

type Methods string

Define methods and encodings type

const (
	GET     Methods = "GET"     // GET method
	POST    Methods = "POST"    // POST method
	PUT     Methods = "PUT"     // PUT method
	PATCH   Methods = "PATCH"   // PATCH method
	DELETE  Methods = "DELETE"  // DELETE method
	OPTIONS Methods = "OPTIONS" // OPTIONS method
	HEAD    Methods = "HEAD"    // HEAD method
	TRACE   Methods = "TRACE"   // TRACE method

)

Define request methods

Jump to

Keyboard shortcuts

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