sihttp

package
v2.3.10 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTLSConfigMinTls

func CreateTLSConfigMinTls(minTlsVersion uint16) *tls.Config

func DefaultInsecureStandardClient

func DefaultInsecureStandardClient() *http.Client

DefaultInsecureStandardClient instantiate http.Client with InsecureSkipVerify set to true

func DefaultStandardClient

func DefaultStandardClient(tlsConfig *tls.Config) *http.Client

DefaultStandardClient instantiate http.Client with input parameter `tlsConfig`

func NewStandardClient

func NewStandardClient(clientTimeout time.Duration, transport *http.Transport) *http.Client

Types

type Client

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

Client is a wrapper of http.Client

func NewClient

func NewClient(client *http.Client, opts ...ClientOption) *Client

NewClient returns Client

func (*Client) Delete

func (hc *Client) Delete(url string, header http.Header, queries map[string]string,
	opts ...RequestOption) ([]byte, error)

func (*Client) DeleteContext

func (hc *Client) DeleteContext(ctx context.Context, url string, header http.Header, queries map[string]string,
	opts ...RequestOption) ([]byte, error)

func (*Client) DeleteDecode

func (hc *Client) DeleteDecode(url string, header http.Header, queries map[string]string,
	res any, opts ...RequestOption) error

func (*Client) DeleteDecodeContext

func (hc *Client) DeleteDecodeContext(ctx context.Context, url string, header http.Header, queries map[string]string,
	res any, opts ...RequestOption) error

func (*Client) Do

func (hc *Client) Do(request *http.Request) (*http.Response, error)

Do is a wrapper of http.Client.Do

func (*Client) DoDecode

func (hc *Client) DoDecode(request *http.Request, res any) error

DoDecode sends Do request and decode response.Body

func (*Client) DoRead

func (hc *Client) DoRead(request *http.Request) ([]byte, error)

DoRead sends Do request and read all data from response.Body

func (*Client) Get

func (hc *Client) Get(url string, header http.Header, queries map[string]string, opts ...RequestOption) ([]byte, error)

func (*Client) GetContext

func (hc *Client) GetContext(ctx context.Context, url string, header http.Header, queries map[string]string, opts ...RequestOption) ([]byte, error)

func (*Client) GetDecode

func (hc *Client) GetDecode(url string, header http.Header, queries map[string]string, res any, opts ...RequestOption) error

func (*Client) GetDecodeContext

func (hc *Client) GetDecodeContext(ctx context.Context, url string, header http.Header, queries map[string]string, res any, opts ...RequestOption) error

func (*Client) Patch

func (hc *Client) Patch(url string, header http.Header, body any, opts ...RequestOption) ([]byte, error)

func (*Client) PatchContext

func (hc *Client) PatchContext(ctx context.Context, url string, header http.Header, body any, opts ...RequestOption) ([]byte, error)

func (*Client) PatchDecode

func (hc *Client) PatchDecode(url string, header http.Header, body any, res any, opts ...RequestOption) error

func (*Client) PatchDecodeContext

func (hc *Client) PatchDecodeContext(ctx context.Context, url string, header http.Header, body any, res any, opts ...RequestOption) error

func (*Client) Post

func (hc *Client) Post(url string, header http.Header, body any, opts ...RequestOption) ([]byte, error)

func (*Client) PostContext

func (hc *Client) PostContext(ctx context.Context, url string, header http.Header, body any, opts ...RequestOption) ([]byte, error)

func (*Client) PostDecode

func (hc *Client) PostDecode(url string, header http.Header, body any, res any, opts ...RequestOption) error

func (*Client) PostDecodeContext

func (hc *Client) PostDecodeContext(ctx context.Context, url string, header http.Header, body any, res any, opts ...RequestOption) error

func (*Client) PostFile

func (hc *Client) PostFile(url string, header http.Header,
	params map[string]string, formKeyName, fileName string) ([]byte, error)

func (*Client) PostFileContext

func (hc *Client) PostFileContext(ctx context.Context, url string, header http.Header,
	params map[string]string, formKeyName, fileName string) ([]byte, error)

func (*Client) Put

func (hc *Client) Put(url string, header http.Header, body any, opts ...RequestOption) ([]byte, error)

func (*Client) PutContext

func (hc *Client) PutContext(ctx context.Context, url string, header http.Header, body any, opts ...RequestOption) ([]byte, error)

func (*Client) PutDecode

func (hc *Client) PutDecode(url string, header http.Header, body any, res any, opts ...RequestOption) error

func (*Client) PutDecodeContext

func (hc *Client) PutDecodeContext(ctx context.Context, url string, header http.Header, body any, res any, opts ...RequestOption) error

func (*Client) Request

func (hc *Client) Request(method string, url string, header http.Header, queries map[string]string,
	body []byte, opts ...RequestOption) ([]byte, error)

func (*Client) RequestContext

func (hc *Client) RequestContext(ctx context.Context, method string, url string, header http.Header,
	queries map[string]string, body []byte, opts ...RequestOption) ([]byte, error)

func (*Client) RequestDecode

func (hc *Client) RequestDecode(method string, url string, header http.Header, queries map[string]string,
	body any, res any, opts ...RequestOption) error

func (*Client) RequestDecodeContext

func (hc *Client) RequestDecodeContext(ctx context.Context, method string, url string, header http.Header,
	queries map[string]string, body any, res any, opts ...RequestOption) error

type ClientOption

type ClientOption interface {
	// contains filtered or unexported methods
}

type ClientOptionFunc

type ClientOptionFunc func(c *Client) error

func WithBaseUrl

func WithBaseUrl(baseUrl string) ClientOptionFunc

func WithDefaultHeaders

func WithDefaultHeaders(defaultHeaders map[string]string) ClientOptionFunc

WithDefaultHeaders set Client with defaultHeaders that will be set on every request

func WithReaderOpt

func WithReaderOpt(opt sio.ReaderOption) ClientOptionFunc

func WithRequestHeaderHmac256

func WithRequestHeaderHmac256(key string, secret []byte) ClientOptionFunc

func WithRequestOpt

func WithRequestOpt(opt RequestOption) ClientOptionFunc

func WithRetryAttempts

func WithRetryAttempts(attempts int) ClientOptionFunc

func WithWriterOpt

func WithWriterOpt(opt sio.WriterOption) ClientOptionFunc

type Error

type Error struct {
	Response *http.Response
	Body     []byte
}

func (Error) Error

func (e Error) Error() string

func (Error) GetStatus

func (e Error) GetStatus(defaultStatusCode int) string

func (Error) GetStatusCode

func (e Error) GetStatusCode(defaultStatusCode int) int

type RequestOption

type RequestOption interface {
	// contains filtered or unexported methods
}

type RequestOptionFunc

type RequestOptionFunc func(c *http.Request) error

func WithBasicAuth

func WithBasicAuth(username, password string) RequestOptionFunc

func WithBearerToken

func WithBearerToken(token string) RequestOptionFunc

func WithHeaderAdd

func WithHeaderAdd(key string, value string) RequestOptionFunc

func WithHeaderHmac256

func WithHeaderHmac256(key string, secret []byte) RequestOptionFunc

func WithHeaderSet

func WithHeaderSet(key string, value string) RequestOptionFunc

func WithTokenSource

func WithTokenSource(tokenSource oauth2.TokenSource) RequestOptionFunc

type Server

type Server struct {
	TLSConf *tls.Config
	Server  *http.Server
	// contains filtered or unexported fields
}

func NewServer

func NewServer(handler http.Handler, tlsConfig *tls.Config,
	addr string, writeTimeout, readTimeout time.Duration) *Server

func NewServerCors

func NewServerCors(handler http.Handler, tlsConfig *tls.Config,
	addr string, writeTimeout, readTimeout time.Duration,
	pem string, key string,
	allowedOrigins, allowedHeaders, allowedMethods []string) *Server

func NewServerTls

func NewServerTls(handler http.Handler, tlsConfig *tls.Config,
	addr string, writeTimeout, readTimeout time.Duration,
	pem string, key string) *Server

func (*Server) Start

func (hs *Server) Start() error

func (*Server) Stop

func (hs *Server) Stop() error

Jump to

Keyboard shortcuts

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