client

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v1.17.0

type Config struct {
	// BaseUrl is the prefix for all requests made by this client.
	// Example: "https://goravel.dev"
	BaseUrl string `json:"base_url"`

	// Timeout specifies the time limit for requests made by this Client.
	// The timeout includes connection time, any redirects, and reading the response body.
	// A Timeout of zero means no timeout (not recommended).
	Timeout time.Duration `json:"timeout"`

	// MaxIdleConns controls the maximum number of idle (keep-alive) connections across all hosts.
	// Increasing this helps performance when making many requests to distinct hosts.
	MaxIdleConns int `json:"max_idle_conns"`

	// MaxIdleConnsPerHost controls the maximum number of idle (keep-alive) connections
	// to keep per-host. This is the most critical setting for high-throughput clients
	// talking to a single backend service.
	MaxIdleConnsPerHost int `json:"max_idle_conns_per_host"`

	// MaxConnsPerHost limits the total number of connections (active + idle) per host.
	// Zero means no limit.
	MaxConnsPerHost int `json:"max_conns_per_host"`

	// IdleConnTimeout is the maximum amount of time an idle (keep-alive) connection
	// will remain idle before closing itself.
	IdleConnTimeout time.Duration `json:"idle_conn_timeout"`
}

type Factory added in v1.17.0

type Factory struct {
	client.Request
	// contains filtered or unexported fields
}

func NewFactory added in v1.17.0

func NewFactory(config *FactoryConfig, json foundation.Json) (*Factory, error)

func (*Factory) AllowStrayRequests added in v1.17.0

func (r *Factory) AllowStrayRequests(patterns []string) client.Factory

func (*Factory) AssertNotSent added in v1.17.0

func (r *Factory) AssertNotSent(assertion func(client.Request) bool) bool

func (*Factory) AssertNothingSent added in v1.17.0

func (r *Factory) AssertNothingSent() bool

func (*Factory) AssertSent added in v1.17.0

func (r *Factory) AssertSent(assertion func(client.Request) bool) bool

func (*Factory) AssertSentCount added in v1.17.0

func (r *Factory) AssertSentCount(count int) bool

func (*Factory) Client added in v1.17.0

func (r *Factory) Client(names ...string) client.Request

func (*Factory) Fake added in v1.17.0

func (r *Factory) Fake(mocks map[string]any) client.Factory

func (*Factory) PreventStrayRequests added in v1.17.0

func (r *Factory) PreventStrayRequests() client.Factory

func (*Factory) Reset added in v1.17.0

func (r *Factory) Reset()

func (*Factory) Response added in v1.17.0

func (r *Factory) Response() client.FakeResponse

func (*Factory) Sequence added in v1.17.0

func (r *Factory) Sequence() client.FakeSequence

type FactoryConfig added in v1.17.0

type FactoryConfig struct {
	Default string            `json:"default_client"`
	Clients map[string]Config `json:"clients"`
}

type FakeResponse added in v1.17.0

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

func NewFakeResponse added in v1.17.0

func NewFakeResponse(json foundation.Json) *FakeResponse

func (*FakeResponse) File added in v1.17.0

func (r *FakeResponse) File(status int, path string) client.Response

func (*FakeResponse) Json added in v1.17.0

func (r *FakeResponse) Json(status int, data any) client.Response

func (*FakeResponse) Make added in v1.17.0

func (r *FakeResponse) Make(status int, body string, header http.Header) client.Response

func (*FakeResponse) OK added in v1.17.0

func (r *FakeResponse) OK() client.Response

func (*FakeResponse) Status added in v1.17.0

func (r *FakeResponse) Status(status int) client.Response

func (*FakeResponse) String added in v1.17.0

func (r *FakeResponse) String(status int, body string) client.Response

type FakeRule added in v1.17.0

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

func NewFakeRule added in v1.17.0

func NewFakeRule(pattern string, handler func(client.Request) client.Response) *FakeRule

func (*FakeRule) Matches added in v1.17.0

func (r *FakeRule) Matches(req *http.Request, clientName string) bool

type FakeSequence added in v1.17.0

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

func NewFakeSequence added in v1.17.0

func NewFakeSequence(json foundation.Json) *FakeSequence

func (*FakeSequence) Push added in v1.17.0

func (r *FakeSequence) Push(response client.Response, count ...int) client.FakeSequence

func (*FakeSequence) PushStatus added in v1.17.0

func (r *FakeSequence) PushStatus(status int, count ...int) client.FakeSequence

func (*FakeSequence) PushString added in v1.17.0

func (r *FakeSequence) PushString(status int, body string, count ...int) client.FakeSequence

func (*FakeSequence) WhenEmpty added in v1.17.0

func (r *FakeSequence) WhenEmpty(response client.Response) client.FakeSequence

type FakeState added in v1.17.0

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

func NewFakeState added in v1.17.0

func NewFakeState(json foundation.Json, mocks map[string]any) *FakeState

func (*FakeState) AllowStrayRequests added in v1.17.0

func (r *FakeState) AllowStrayRequests(patterns []string)

func (*FakeState) AssertSent added in v1.17.0

func (r *FakeState) AssertSent(f func(client.Request) bool) bool

func (*FakeState) AssertSentCount added in v1.17.0

func (r *FakeState) AssertSentCount(count int) bool

func (*FakeState) Match added in v1.17.0

func (r *FakeState) Match(req *http.Request, name string) func(client.Request) client.Response

func (*FakeState) PreventStrayRequests added in v1.17.0

func (r *FakeState) PreventStrayRequests()

func (*FakeState) Record added in v1.17.0

func (r *FakeState) Record(req client.Request)

func (*FakeState) ShouldPreventStray added in v1.17.0

func (r *FakeState) ShouldPreventStray(url string) bool

type FakeTransport added in v1.17.0

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

func NewFakeTransport added in v1.17.0

func NewFakeTransport(state *FakeState, base http.RoundTripper, json foundation.Json) *FakeTransport

func (*FakeTransport) RoundTrip added in v1.17.0

func (r *FakeTransport) RoundTrip(req *http.Request) (*http.Response, error)

type Request

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

func NewRequest

func NewRequest(client *http.Client, json foundation.Json, baseUrl string, clientName string) *Request

func (*Request) Accept

func (r *Request) Accept(contentType string) client.Request

func (*Request) AcceptJSON

func (r *Request) AcceptJSON() client.Request

func (*Request) AsForm

func (r *Request) AsForm() client.Request

func (*Request) BaseUrl added in v1.17.0

func (r *Request) BaseUrl(url string) client.Request

func (*Request) Body added in v1.17.0

func (r *Request) Body() string

func (*Request) ClientName added in v1.17.0

func (r *Request) ClientName() string

func (*Request) Clone

func (r *Request) Clone() client.Request

func (*Request) Delete

func (r *Request) Delete(uri string, body io.Reader) (client.Response, error)

func (*Request) FlushHeaders

func (r *Request) FlushHeaders() client.Request

func (*Request) Get

func (r *Request) Get(uri string) (client.Response, error)

func (*Request) Head

func (r *Request) Head(uri string) (client.Response, error)

func (*Request) Header added in v1.17.0

func (r *Request) Header(key string) string

func (*Request) Headers added in v1.17.0

func (r *Request) Headers() http.Header

func (*Request) HttpClient added in v1.17.0

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

func (*Request) Input added in v1.17.0

func (r *Request) Input(key string) any

func (*Request) Method added in v1.17.0

func (r *Request) Method() string

func (*Request) Options

func (r *Request) Options(uri string) (client.Response, error)

func (*Request) Patch

func (r *Request) Patch(uri string, body io.Reader) (client.Response, error)

func (*Request) Post

func (r *Request) Post(uri string, body io.Reader) (client.Response, error)

func (*Request) Put

func (r *Request) Put(uri string, body io.Reader) (client.Response, error)

func (*Request) ReplaceHeaders

func (r *Request) ReplaceHeaders(headers map[string]string) client.Request

func (*Request) Url added in v1.17.0

func (r *Request) Url() string

func (*Request) WithBasicAuth

func (r *Request) WithBasicAuth(username, password string) client.Request

func (*Request) WithContext

func (r *Request) WithContext(ctx context.Context) client.Request

func (*Request) WithCookie

func (r *Request) WithCookie(cookie *http.Cookie) client.Request

func (*Request) WithCookies

func (r *Request) WithCookies(cookies []*http.Cookie) client.Request

func (*Request) WithHeader

func (r *Request) WithHeader(key, value string) client.Request

func (*Request) WithHeaders

func (r *Request) WithHeaders(headers map[string]string) client.Request

func (*Request) WithQueryParameter

func (r *Request) WithQueryParameter(key, value string) client.Request

func (*Request) WithQueryParameters

func (r *Request) WithQueryParameters(params map[string]string) client.Request

func (*Request) WithQueryString

func (r *Request) WithQueryString(query string) client.Request

func (*Request) WithToken

func (r *Request) WithToken(token string, ttype ...string) client.Request

func (*Request) WithUrlParameter

func (r *Request) WithUrlParameter(key, value string) client.Request

func (*Request) WithUrlParameters

func (r *Request) WithUrlParameters(params map[string]string) client.Request

func (*Request) WithoutHeader

func (r *Request) WithoutHeader(key string) client.Request

func (*Request) WithoutToken

func (r *Request) WithoutToken() client.Request

type Response

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

func NewResponse

func NewResponse(response *http.Response, json foundation.Json) *Response

func (*Response) Accepted

func (r *Response) Accepted() bool

func (*Response) BadRequest

func (r *Response) BadRequest() bool

func (*Response) Bind added in v1.17.0

func (r *Response) Bind(value any) error

func (*Response) Body

func (r *Response) Body() (string, error)

func (*Response) ClientError

func (r *Response) ClientError() bool

func (*Response) Conflict

func (r *Response) Conflict() bool

func (*Response) Cookie

func (r *Response) Cookie(name string) *http.Cookie

func (*Response) Cookies

func (r *Response) Cookies() []*http.Cookie

func (*Response) Created

func (r *Response) Created() bool

func (*Response) Failed

func (r *Response) Failed() bool

func (*Response) Forbidden

func (r *Response) Forbidden() bool

func (*Response) Found

func (r *Response) Found() bool

func (*Response) Header

func (r *Response) Header(name string) string

func (*Response) Headers

func (r *Response) Headers() http.Header

func (*Response) Json

func (r *Response) Json() (map[string]any, error)

func (*Response) MovedPermanently

func (r *Response) MovedPermanently() bool

func (*Response) NoContent

func (r *Response) NoContent() bool

func (*Response) NotFound

func (r *Response) NotFound() bool

func (*Response) OK

func (r *Response) OK() bool

func (*Response) Origin added in v1.17.0

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

func (*Response) PaymentRequired

func (r *Response) PaymentRequired() bool

func (*Response) Redirect

func (r *Response) Redirect() bool

func (*Response) RequestTimeout

func (r *Response) RequestTimeout() bool

func (*Response) ServerError

func (r *Response) ServerError() bool

func (*Response) Status

func (r *Response) Status() int

func (*Response) Stream added in v1.17.0

func (r *Response) Stream() (io.ReadCloser, error)

func (*Response) Successful

func (r *Response) Successful() bool

func (*Response) TooManyRequests

func (r *Response) TooManyRequests() bool

func (*Response) Unauthorized

func (r *Response) Unauthorized() bool

func (*Response) UnprocessableEntity

func (r *Response) UnprocessableEntity() bool

Jump to

Keyboard shortcuts

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