Documentation
¶
Index ¶
- func CustomDecodeRequest(ctx context.Context, request *http.Request, req proto.Message) (bool, error)
- func DecodeHttpBody(ctx context.Context, request *http.Request, body *httpbody.HttpBody) error
- func DecodeHttpRequest(ctx context.Context, request *http.Request, req *rpchttp.HttpRequest) error
- func DecodeRequest(ctx context.Context, request *http.Request, req proto.Message, ...) error
- func EncodeHttpBody(ctx context.Context, response http.ResponseWriter, resp *httpbody.HttpBody) error
- func EncodeHttpResponse(ctx context.Context, response http.ResponseWriter, resp *rpchttp.HttpResponse) error
- func EncodeResponse(ctx context.Context, response http.ResponseWriter, resp proto.Message, ...) error
- func Invoke(middleware Middleware, response http.ResponseWriter, request *http.Request, ...)
- type Middleware
- type Option
- func ErrorEncoder(encoder goose.ErrorEncoder) Option
- func FailFast() Option
- func MarshalOptions(opts protojson.MarshalOptions) Option
- func Middlewares(middlewares ...Middleware) Option
- func OnValidationErrCallback(OnValidationErrCallback goose.OnValidationErrCallback) Option
- func UnmarshalOptions(opts protojson.UnmarshalOptions) Option
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CustomDecodeRequest ¶
func CustomDecodeRequest(ctx context.Context, request *http.Request, req proto.Message) (bool, error)
CustomDecodeRequest provides custom request decoding functionality Parameters:
- ctx: Context object
- request: HTTP request object
- req: Proto.Message to be decoded
Returns:
- bool: Indicates whether custom decoding was performed
- error: Any error that occurred during decoding
Behavior:
- Checks if req implements UnmarshalRequest method
- If implemented, invokes the method for decoding
- If not implemented, returns false indicating no custom decoding was done
func DecodeHttpBody ¶
DecodeHttpBody decodes HTTP request body into HttpBody object Parameters:
- ctx: Context object
- request: HTTP request object
- body: Target HttpBody object
Returns:
- error: Decoding error if any
Behavior:
- Reads the request body data
- Sets HttpBody's Data and ContentType fields
func DecodeHttpRequest ¶
DecodeHttpRequest decodes HTTP request into HttpRequest object Parameters:
- ctx: Context object
- request: HTTP request object
- request: Target HttpRequest object
Returns:
- error: Decoding error if any
Behavior:
- Reads the request body data
- Sets method, URI, headers and body fields
func DecodeRequest ¶
func DecodeRequest(ctx context.Context, request *http.Request, req proto.Message, unmarshalOptions protojson.UnmarshalOptions) error
DecodeRequest decodes HTTP request body into a proto.Message Parameters:
- ctx: Context object
- request: HTTP request object
- req: Target proto.Message
- unmarshalOptions: protojson unmarshal options
Returns:
- error: Decoding error if any
Behavior:
- Reads the request body
- Unmarshals the data into target proto.Message using protojson
func EncodeHttpBody ¶
func EncodeHttpBody(ctx context.Context, response http.ResponseWriter, resp *httpbody.HttpBody) error
EncodeHttpBody encodes an httpbody.HttpBody into an HTTP response. Sets Content-Type from the HttpBody and status code to 200 OK.
Parameters:
ctx - context.Context for the request response - http.ResponseWriter to write the response resp - *httpbody.HttpBody to encode
Returns:
error - if writing fails
func EncodeHttpResponse ¶
func EncodeHttpResponse(ctx context.Context, response http.ResponseWriter, resp *rpchttp.HttpResponse) error
EncodeHttpResponse encodes an rpchttp.HttpResponse into an HTTP response. Sets headers, status code and body from the HttpResponse.
Parameters:
ctx - context.Context for the request response - http.ResponseWriter to write the response resp - *rpchttp.HttpResponse to encode
Returns:
error - if writing fails
func EncodeResponse ¶
func EncodeResponse(ctx context.Context, response http.ResponseWriter, resp proto.Message, marshalOptions protojson.MarshalOptions) error
EncodeResponse encodes a protobuf message as JSON into an HTTP response. Sets Content-Type to application/json and status code to 200 OK.
Parameters:
ctx - context.Context for the request response - http.ResponseWriter to write the response resp - proto.Message to encode marshalOptions - protojson.MarshalOptions for JSON encoding
Returns:
error - if encoding or writing fails
func Invoke ¶
func Invoke(middleware Middleware, response http.ResponseWriter, request *http.Request, invoke http.HandlerFunc, routeInfo *goose.RouteInfo)
Invoke wraps a Middleware and a final handler function into an http.Handler. If the middleware is nil, directly calls the final handler. Otherwise, executes the middleware chain ending with the final handler.
Parameters:
middleware - Middleware function to execute (can be nil) invoke - http.HandlerFunc representing the final handler response - http.ResponseWriter to write the HTTP response request - *http.Request representing the incoming HTTP request routeInfo - *goose.RouteInfo representing the route information
Types ¶
type Middleware ¶
type Middleware func(response http.ResponseWriter, request *http.Request, invoker http.HandlerFunc)
Middleware defines a function type for HTTP middleware. It receives an http.ResponseWriter, an http.Request, and the next handler (invoker) in the chain.
Parameters:
response - http.ResponseWriter to write the HTTP response request - *http.Request containing the HTTP request data invoker - http.HandlerFunc representing the next handler in the middleware chain
func Chain ¶
func Chain(middlewares ...Middleware) Middleware
Chain combines multiple Middleware functions into a single Middleware. If no middlewares are provided, returns nil. If one middleware is provided, returns that middleware. If multiple middlewares are provided, returns a middleware that executes them in chain.
Parameters:
middlewares - variadic list of Middleware functions to chain together
Returns:
Middleware - a single middleware function representing the entire chain
type Option ¶
type Option func(o *options)
Option defines a function type for modifying server options
func ErrorEncoder ¶
func ErrorEncoder(encoder goose.ErrorEncoder) Option
ErrorEncoder configures a custom error encoder
Parameters:
- encoder: The error encoder to use
Returns:
- Option: A function that sets the error encoder 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 responses
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 UnmarshalOptions ¶
func UnmarshalOptions(opts protojson.UnmarshalOptions) Option
UnmarshalOptions sets the protojson unmarshal options used for decoding requests
Parameters:
- opts: The protojson unmarshal options to use
Returns:
- Option: A function that sets the unmarshal options
type Options ¶
type Options interface {
// UnmarshalOptions returns the protojson unmarshal options used for decoding requests
UnmarshalOptions() protojson.UnmarshalOptions
// MarshalOptions returns the protojson marshal options used for encoding responses
MarshalOptions() protojson.MarshalOptions
// ErrorEncoder returns the error encoder used for encoding error responses
ErrorEncoder() goose.ErrorEncoder
// 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
}
Options interface defines methods to access all configurable options for the server
func NewOptions ¶
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