call

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2022 License: MIT Imports: 6 Imported by: 0

README

Call

Documentation

Index

Constants

View Source
const HEADER_AUTHORIZATION = "Authorization"
View Source
const HEADER_CONTENT_TYPE = "Content-Type"

Variables

This section is empty.

Functions

func BuildUrl

func BuildUrl[T any](base string, options T) (string, error)

func Call

func Call[R any](
	options CallOptions,
	callback func(resp *http.Response, bytes []byte) (R, error),
) (R, error)

func FromBytes

func FromBytes[T any](data []byte) (*T, error)

func Read

func Read(resp *http.Response) ([]byte, error)

Types

type CallOptionFunction

type CallOptionFunction func(c *CallOptions)

func WithBase

func WithBase(base string) CallOptionFunction

func WithBody

func WithBody(b any) CallOptionFunction

func WithHeader

func WithHeader(name string, value string) CallOptionFunction

func WithMethod

func WithMethod(method string) CallOptionFunction

func WithQuery

func WithQuery(q any) CallOptionFunction

type CallOptions

type CallOptions struct {
	Method  string
	Base    string
	Headers HeaderMap
	Query   any
	Body    any
}

func NewCallOptions

func NewCallOptions(options ...CallOptionFunction) CallOptions

func (*CallOptions) GetBody

func (c *CallOptions) GetBody() (io.Reader, error)

func (*CallOptions) GetRequest

func (c *CallOptions) GetRequest() (*http.Request, error)

func (*CallOptions) GetUrl

func (c *CallOptions) GetUrl() (string, error)

type ContentType

type ContentType string
const CONTENT_TYPE_FORM_URLENCODED ContentType = "application/x-www-form-urlencoded; param=value"
const CONTENT_TYPE_JSON ContentType = "application/json"
type Header struct {
	*http.Header
}

func NewHeader

func NewHeader(header *http.Header) Header

func (*Header) SetAuthorization

func (h *Header) SetAuthorization(authorization string)

func (*Header) SetContentType

func (h *Header) SetContentType(contentType ContentType)

type HeaderMap

type HeaderMap = map[string]string

type Result

type Result[T any, E any] struct {
	Value T
	Error E
}

func Err

func Err[E any](error E) Result[any, E]

func Ok

func Ok[T any](value T) Result[T, any]

Jump to

Keyboard shortcuts

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