xhttpclient

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 24 Imported by: 2

README

xhttpclient

Documentation

Index

Constants

View Source
const (
	ContentTypeValueJSON           = "application/json; charset=utf-8"
	ContentTypeValueFormUrlencoded = "application/x-www-form-urlencoded"
)

Variables

This section is empty.

Functions

func BodyCodecResponseIsWrongGTE400

func BodyCodecResponseIsWrongGTE400(resp *http.Response) bool

func DefaultClient

func DefaultClient() *http.Client

func DefaultTransport

func DefaultTransport() *http.Transport

func ResponseIsSuccessfulGTE200LTE299

func ResponseIsSuccessfulGTE200LTE299(resp *http.Response) bool

Types

type BodyCodec

type BodyCodec interface {
	Get() BodyCodec
	Put(bc BodyCodec)

	Encode(body any) (io.Reader, error)
	Decode(r io.Reader, v any) error
}
var (
	BodyCodecFormUrlencodedAndJSON BodyCodec = &bodyCodecFormUrlencodedAndJSON{}
)
var (
	BodyCodecJSON BodyCodec = &bodyCodecJSON{}
)
var (
	BodyCodecMultipart BodyCodec = &bodyCodecMultipart{}
)

type BodyCodecDecodeWrong

type BodyCodecDecodeWrong interface {
	DecodeWrong(r io.Reader, v any) error
}

type BodyCodecOnReceive

type BodyCodecOnReceive interface {
	OnReceive(req *http.Request, resp *http.Response)
}

type BodyCodecOnSend

type BodyCodecOnSend interface {
	OnSend(req *http.Request)
}

type BodyCodecResponseIsSuccessful

type BodyCodecResponseIsSuccessful interface {
	IsSuccessful(resp *http.Response) bool
}

type BodyCodecResponseIsWrong

type BodyCodecResponseIsWrong interface {
	IsWrong(resp *http.Response) bool
}

type BodyHeaderAccept

type BodyHeaderAccept interface {
	Accept() string
}

type BodyHeaderAcceptEncoding

type BodyHeaderAcceptEncoding interface {
	AcceptEncoding() string
}

type BodyHeaderContentEncoding

type BodyHeaderContentEncoding interface {
	ContentEncoding() string
}

type BodyHeaderContentLength

type BodyHeaderContentLength interface {
	ContentLength() int
}

type BodyHeaderContentType

type BodyHeaderContentType interface {
	ContentType() string
}

type XClient

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

func NewClient

func NewClient() *XClient

func (*XClient) AddHeader

func (xc *XClient) AddHeader(key, value string) *XClient

func (*XClient) BaseURL

func (xc *XClient) BaseURL(baseURL string) *XClient

func (*XClient) Clone

func (xc *XClient) Clone() *XClient

func (*XClient) Do

func (xc *XClient) Do(successV, wrongV any, xReq *XRequestBuilder) (resp *http.Response, respBody []byte, err error)

func (*XClient) DoOnceWithBodyCodec

func (xc *XClient) DoOnceWithBodyCodec(bodyCodec BodyCodec, successV, wrongV any, xReq *XRequestBuilder) (resp *http.Response, respBody []byte, err error)

func (*XClient) DoWithRaw

func (xc *XClient) DoWithRaw(xReq *XRequestBuilder) (req *http.Request, resp *http.Response, err error)

func (*XClient) Header

func (xc *XClient) Header(header http.Header) *XClient

func (*XClient) SetBasicAuth

func (xc *XClient) SetBasicAuth(username, password string) *XClient

func (*XClient) SetHeader

func (xc *XClient) SetHeader(key, value string) *XClient

func (*XClient) WithBodyCodec

func (xc *XClient) WithBodyCodec(bodyCodec BodyCodec) *XClient

func (*XClient) WithBodyCodecJSON

func (xc *XClient) WithBodyCodecJSON() *XClient

func (*XClient) WithCheckRedirect

func (xc *XClient) WithCheckRedirect(fn func(req *http.Request, via []*http.Request) error) *XClient

func (*XClient) WithClient

func (xc *XClient) WithClient(c *http.Client) *XClient

func (*XClient) WithJar

func (xc *XClient) WithJar(jar *cookiejar.Jar) *XClient

func (*XClient) WithTimeout

func (xc *XClient) WithTimeout(d time.Duration) *XClient

func (*XClient) WithTransport

func (xc *XClient) WithTransport(transport http.RoundTripper) *XClient

type XMultipartWriter

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

func NewMultipartWriter

func NewMultipartWriter() *XMultipartWriter

func (*XMultipartWriter) Boundary

func (xmw *XMultipartWriter) Boundary() string

func (*XMultipartWriter) FormDataContentType

func (xmw *XMultipartWriter) FormDataContentType() string

FormDataContentType returns the Content-Type for an HTTP multipart/form-data with this Writer's Boundary.

Copied from mime/multipart/writer.go

func (*XMultipartWriter) SetBoundary

func (xmw *XMultipartWriter) SetBoundary(boundary string) *XMultipartWriter

func (*XMultipartWriter) WriteWithField

func (xmw *XMultipartWriter) WriteWithField(fieldname string, r io.Reader) *XMultipartWriter

func (*XMultipartWriter) WriteWithFieldValue

func (xmw *XMultipartWriter) WriteWithFieldValue(fieldname, value string) *XMultipartWriter

func (*XMultipartWriter) WriteWithFile

func (xmw *XMultipartWriter) WriteWithFile(fieldname, filename string) *XMultipartWriter

func (*XMultipartWriter) WriteWithHeader

func (xmw *XMultipartWriter) WriteWithHeader(header textproto.MIMEHeader, r io.Reader) *XMultipartWriter

type XRequestBuilder

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

func NewConnect

func NewConnect() *XRequestBuilder

func NewDelete

func NewDelete() *XRequestBuilder

func NewGet

func NewGet() *XRequestBuilder

func NewHead

func NewHead() *XRequestBuilder

func NewOptions

func NewOptions() *XRequestBuilder

func NewPatch

func NewPatch() *XRequestBuilder

func NewPost

func NewPost() *XRequestBuilder

func NewPut

func NewPut() *XRequestBuilder

func NewTrace

func NewTrace() *XRequestBuilder

func (*XRequestBuilder) AddHeader

func (xr *XRequestBuilder) AddHeader(key, value string) *XRequestBuilder

func (*XRequestBuilder) AddQuery

func (xr *XRequestBuilder) AddQuery(key, value string) *XRequestBuilder

func (*XRequestBuilder) Body

func (xr *XRequestBuilder) Body(body any) *XRequestBuilder

func (*XRequestBuilder) Header

func (xr *XRequestBuilder) Header(header http.Header) *XRequestBuilder

func (*XRequestBuilder) Path

func (xr *XRequestBuilder) Path(elements ...string) *XRequestBuilder

func (*XRequestBuilder) Query

func (xr *XRequestBuilder) Query(query urlpkg.Values) *XRequestBuilder

func (*XRequestBuilder) SetBasicAuth

func (xr *XRequestBuilder) SetBasicAuth(username, password string) *XRequestBuilder

func (*XRequestBuilder) SetHeader

func (xr *XRequestBuilder) SetHeader(key, value string) *XRequestBuilder

func (*XRequestBuilder) SetQuery

func (xr *XRequestBuilder) SetQuery(key, value string) *XRequestBuilder

func (*XRequestBuilder) WithContext

func (xr *XRequestBuilder) WithContext(ctx context.Context) *XRequestBuilder

Jump to

Keyboard shortcuts

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