fetch

package
v0.82.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes

func Bytes(resp Response) ([]byte, error)

func Decode

func Decode(resp Response, target any) error

func DownloadTo

func DownloadTo(resp Response, box sandbox.Root, path string) error

func GetJSON

func GetJSON[T any](url string) (T, error)

func JSON

func JSON[T any](resp Response) (T, error)

func PathEscape

func PathEscape(value string) string

func QueryEscape

func QueryEscape(value string) string

func Text

func Text(resp Response) (string, error)

func URLTemplate

func URLTemplate(tmpl string, params map[string]string) (string, error)

func URLWithQuery

func URLWithQuery(baseURL string, params map[string]string) (string, error)

Types

type HTTPMethod

type HTTPMethod string
const (
	HTTPMethodGET     HTTPMethod = "GET"
	HTTPMethodPOST    HTTPMethod = "POST"
	HTTPMethodPUT     HTTPMethod = "PUT"
	HTTPMethodPATCH   HTTPMethod = "PATCH"
	HTTPMethodDELETE  HTTPMethod = "DELETE"
	HTTPMethodHEAD    HTTPMethod = "HEAD"
	HTTPMethodOPTIONS HTTPMethod = "OPTIONS"
)

func AllHTTPMethod

func AllHTTPMethod() []HTTPMethod

func ParseHTTPMethod

func ParseHTTPMethod(s string) (HTTPMethod, error)

func (HTTPMethod) String

func (e HTTPMethod) String() string

type Request

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

func BasicAuth

func BasicAuth(req Request, username string, password string) Request

func BearerAuth

func BearerAuth(req Request, token string) Request

func Body

func Body(req Request, data any) Request

func Dump added in v0.72.0

func Dump(req Request) Request

func FormData

func FormData(req Request, data map[string]string) Request
func Header(req Request, name string, value string) Request

func MaxBodySize

func MaxBodySize(req Request, limit int64) Request

func Method

func Method(req Request, method HTTPMethod) Request

func New

func New(url string) Request

func NewExternal

func NewExternal(url string) Request

func OnError added in v0.72.0

func OnError(req Request, target any) Request

func OnSuccess added in v0.72.0

func OnSuccess(req Request, target any) Request

func Retry

func Retry(req Request, maxAttempts int, delayMs int) Request

func Timeout

func Timeout(req Request, d time.Duration) Request

func Trace added in v0.72.0

func Trace(req Request) Request

func Transport

func Transport(req Request, t *http.Transport) Request

func WithContext

func WithContext(req Request, h ctxpkg.Handle) Request

type Response

type Response struct {
	StatusCode int
	Status     string
	// contains filtered or unexported fields
}

func CheckStatus

func CheckStatus(resp Response) (Response, error)

func Do

func Do(req Request) (Response, error)

func Get

func Get(url string) (Response, error)

func GetCtx

func GetCtx(h ctxpkg.Handle, url string) (Response, error)

func Post

func Post(url string, data any) (Response, error)

func PostCtx

func PostCtx(h ctxpkg.Handle, url string, data any) (Response, error)

func SafeGet

func SafeGet(url string) (Response, error)

func SafeGetCtx

func SafeGetCtx(h ctxpkg.Handle, url string) (Response, error)

func SessionDo

func SessionDo(s Session, req Request) (Response, error)

func SessionGet

func SessionGet(s Session, url string) (Response, error)

func SessionPost

func SessionPost(s Session, url string, data any) (Response, error)

func (Response) Bytes

func (r Response) Bytes() ([]byte, error)

func (Response) Close

func (r Response) Close() error

func (Response) Decode

func (r Response) Decode(target any) error

func (Response) DumpText added in v0.72.0

func (r Response) DumpText() string

func (Response) Header

func (r Response) Header(name string) string

func (Response) JSON

func (r Response) JSON[T any]() (T, error)

func (*Response) Raw

func (r *Response) Raw() *http.Response

func (Response) Text

func (r Response) Text() (string, error)

func (Response) TraceInfo added in v0.72.0

func (r Response) TraceInfo() TraceInfo

type Session

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

func NewSession

func NewSession() Session

func SessionHeader

func SessionHeader(s Session, name string, value string) Session

func SessionTimeout

func SessionTimeout(s Session, d time.Duration) Session

func SessionTransport

func SessionTransport(s Session, t *http.Transport) Session

type TraceInfo added in v0.72.0

type TraceInfo struct {
	TotalTime         time.Duration
	DNSLookupTime     time.Duration
	TCPConnectTime    time.Duration
	TLSHandshakeTime  time.Duration
	FirstResponseTime time.Duration
	ResponseTime      time.Duration
	RemoteAddr        string
}

Source Files

  • fetch.go

Jump to

Keyboard shortcuts

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