client

package
v1.7.18 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeHttpBody

func DecodeHttpBody(ctx context.Context, response *http.Response, resp *httpbody.HttpBody) error

DecodeHttpBody decodes an HTTP response into an HttpBody message. It extracts the content type from the response headers and copies the raw response body data.

Parameters:

  • ctx: The context.Context for the request
  • response: The HTTP response to decode
  • resp: The HttpBody message to populate with response data

Returns:

  • error: Any error that occurred during decoding, or nil if successful

func DecodeHttpResponse

func DecodeHttpResponse(ctx context.Context, response *http.Response, resp *rpchttp.HttpResponse) error

DecodeHttpResponse decodes an HTTP response into an HttpResponse message. It extracts the status code, reason phrase, headers, and body from the HTTP response.

Parameters:

  • ctx: The context.Context for the request
  • response: The HTTP response to decode
  • resp: The HttpResponse message to populate with response data

Returns:

  • error: Any error that occurred during decoding, or nil if successful

func DecodeMessage

func DecodeMessage(ctx context.Context, response *http.Response, resp proto.Message, unmarshalOptions protojson.UnmarshalOptions) error

DecodeMessage decodes an HTTP response into a protobuf message. It reads the response body, unmarshals the JSON data into the provided protobuf message, and properly closes the response body.

Parameters:

  • ctx: The context.Context for the request
  • response: The HTTP response to decode
  • resp: The protobuf message to unmarshal the response data into
  • unmarshalOptions: Options for protobuf JSON unmarshaling

Returns:

  • error: Any error that occurred during decoding, or nil if successful

func EncodeHttpBody

func EncodeHttpBody(ctx context.Context, req *httpbody.HttpBody, header http.Header, body io.Writer) error

EncodeHttpBody encodes an HttpBody message into an HTTP request. It writes the raw data from the HttpBody to the body writer and sets the content type header from the HttpBody.

Parameters:

  • ctx: The context.Context for the request
  • req: The HttpBody message to encode
  • header: The HTTP headers to set content type information
  • body: The io.Writer to write the encoded message data

Returns:

  • error: Any error that occurred during encoding, or nil if successful

func EncodeHttpRequest

func EncodeHttpRequest(ctx context.Context, req *rpchttp.HttpRequest, header http.Header, body io.Writer) error

EncodeHttpRequest encodes an HttpRequest message into an HTTP request. It writes the body data from the HttpRequest to the body writer and adds all headers from the HttpRequest to the header collection.

Parameters:

  • ctx: The context.Context for the request
  • req: The HttpRequest message to encode
  • header: The HTTP headers to add header information from the HttpRequest
  • body: The io.Writer to write the encoded message data

Returns:

  • error: Any error that occurred during encoding, or nil if successful

func EncodeMessage

func EncodeMessage(ctx context.Context, req proto.Message, header http.Header, body io.Writer, marshalOptions protojson.MarshalOptions) error

EncodeMessage encodes a protobuf message into an HTTP request. It marshals the protobuf message to JSON, writes it to the body writer, and sets the appropriate content type header.

Parameters:

  • ctx: The context.Context for the request
  • req: The protobuf message to encode
  • header: The HTTP headers to set content type information
  • body: The io.Writer to write the encoded message data
  • marshalOptions: Options for protobuf JSON marshaling

Returns:

  • error: Any error that occurred during encoding, or nil if successful

func Invoke

func Invoke(middleware Middleware, cli *http.Client, request *http.Request, routeInfo *goose.RouteInfo) (*http.Response, error)

Invoke executes an HTTP request with the given middleware. If no middleware is provided, it directly executes the request using the HTTP client.

Parameters:

  • ctx: The context.Context for the request
  • middleware: The middleware to apply to the request (can be nil)
  • cli: The HTTP client to use for the request
  • request: The HTTP request to execute

Returns:

  • *http.Response: The HTTP response from the request
  • error: Any error that occurred during the request, or nil if successful

Types

type Invoker

type Invoker func(cli *http.Client, request *http.Request) (*http.Response, error)

Invoker is a function type that defines how to invoke an HTTP request. It takes an HTTP client, and an HTTP request, and returns an HTTP response or an error.

Parameters:

  • cli: The HTTP client to use for the request
  • request: The HTTP request to invoke

Returns:

  • *http.Response: The HTTP response from the request
  • error: Any error that occurred during the request, or nil if successful

type Middleware

type Middleware func(cli *http.Client, request *http.Request, invoker Invoker) (*http.Response, error)

Middleware is a function type that defines middleware for HTTP requests. It takes an HTTP client, an HTTP request, and the next invoker in the chain, and returns an HTTP response or an error.

Parameters:

  • cli: The HTTP client to use for the request
  • request: The HTTP request to process
  • invoker: The next invoker in the middleware chain

Returns:

  • *http.Response: The HTTP response from the request
  • error: Any error that occurred during the request, or nil if successful

func Chain

func Chain(middlewares ...Middleware) Middleware

Chain combines multiple middleware functions into a single middleware function. It creates a chain where each middleware calls the next one in the sequence.

Parameters:

  • middlewares: A variadic list of middleware functions to chain together

Returns:

  • Middleware: A single middleware function that represents the entire chain

type Option

type Option func(o *options)

Option defines a function type for modifying client options

func Client

func Client(client *http.Client) Option

Client sets the HTTP client to be used for making requests

Parameters:

  • client: The HTTP client to use

Returns:

  • Option: A function that sets the client option

func ErrorEncoder

func ErrorEncoder(decoder goose.ErrorDecoder) Option

ErrorEncoder configures a custom error decoder

Parameters:

  • decoder: The error decoder to use

Returns:

  • Option: A function that sets the error decoder option

func ErrorFactory

func ErrorFactory(factory goose.ErrorFactory) Option

ErrorFactory sets the error factory to be used for creating error instances

Parameters:

  • factory: The error factory to use

Returns:

  • Option: A function that sets the error factory option

func FailFast

func FailFast() Option

FailFast enables fail-fast mode

Returns:

  • Option: A function that enables fail-fast mode

func MarshalOptions

func MarshalOptions(opts protojson.MarshalOptions) Option

MarshalOptions sets the protojson marshal options used for encoding requests

Parameters:

  • opts: The protojson marshal options to use

Returns:

  • Option: A function that sets the marshal options

func Middlewares

func Middlewares(middlewares ...Middleware) Option

Middlewares appends middlewares to the chain of middlewares

Parameters:

  • middlewares: A variadic list of middlewares to append

Returns:

  • Option: A function that appends the middlewares

func OnValidationErrCallback

func OnValidationErrCallback(OnValidationErrCallback goose.OnValidationErrCallback) Option

OnValidationErrCallback sets the validation error callback

Parameters:

  • OnValidationErrCallback: The validation error callback to use

Returns:

  • Option: A function that sets the validation error callback

func Resolvers

func Resolvers(resolver resolver.Resolver) Option

func UnmarshalOptions

func UnmarshalOptions(opts protojson.UnmarshalOptions) Option

UnmarshalOptions sets the protojson unmarshal options used for decoding responses

Parameters:

  • opts: The protojson unmarshal options to use

Returns:

  • Option: A function that sets the unmarshal options

type Options

type Options interface {
	// Client returns the HTTP client used for making requests
	Client() *http.Client

	// UnmarshalOptions returns the protojson unmarshal options used for decoding responses
	UnmarshalOptions() protojson.UnmarshalOptions

	// MarshalOptions returns the protojson marshal options used for encoding requests
	MarshalOptions() protojson.MarshalOptions

	// ErrorDecoder returns the error decoder used for decoding error responses
	ErrorDecoder() goose.ErrorDecoder

	// ErrorFactory returns the error factory used for creating error instances
	ErrorFactory() goose.ErrorFactory

	// Middlewares returns the list of middlewares applied to requests
	Middlewares() []Middleware

	// ShouldFailFast indicates if fail-fast mode is enabled
	ShouldFailFast() bool

	// OnValidationErrCallback returns the validation error callback
	OnValidationErrCallback() goose.OnValidationErrCallback

	// Resolver returns the resolver used for resolving URLs
	Resolver() resolver.Resolver
}

Options interface defines methods to access all configurable options for the client

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions creates a new Options instance with default values and applies the provided options

Parameters:

  • opts: A variadic list of Option functions to apply

Returns:

  • Options: A new Options instance with the applied options

Directories

Path Synopsis
Package resolver provides URL resolution functionality for the goose client
Package resolver provides URL resolution functionality for the goose client

Jump to

Keyboard shortcuts

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