http

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chain

func Chain(middlewares ...echo.MiddlewareFunc) echo.MiddlewareFunc

Chain is a helper function that chains multiple echo.MiddlewareFunc into one. It processes the request in the order the middlewares are passed.

func NewEchoServer

func NewEchoServer(opts ...ServerOption) *echo.Echo

NewEchoServer allocates a new echo.Echo instance with default configurations.

func NewErrorHandler

func NewErrorHandler(responseCodec string) echo.HTTPErrorHandler

NewErrorHandler allocates a new echo.HTTPErrorHandler instance.

This routine generates Error structures to comply with a homogeneous error format.

func NewPaginationOptions

func NewPaginationOptions(c echo.Context) []paging.Option

NewPaginationOptions creates a new set of pagination options based on the query parameters from the given echo context. It uses the "page_size" and "page_token" query parameters to set the limit and page token for pagination.

func RegisterServerEndpoints

func RegisterServerEndpoints(e *echo.Echo, config application.Application, ctrls []Controller) string

RegisterServerEndpoints registers `ctrls` (slice of Controller) into `e` (echo.Echo).

Uses application.Application.Version.Major() value as path prefix for versioned endpoints.

func Transactional

func Transactional(opts ...TransactionalOption) echo.MiddlewareFunc

Transactional is an Echo middleware that wraps the request in a database transaction. If the request handler returns an error, the transaction will be rolled back. If the request handler completes successfully, the transaction will be committed.

If a persistence.TxManager is provided via the WithTxManager option, the request handler will be executed within a set of transactions managed by the provided manager. This allows for executing multiple database transactions in a single request, which can be useful for complex operations that require multiple steps to be executed atomically.

If you want to use a specific transaction factory, you can enable it by passing the WithTxFactory option to set it.

Types

type Controller

type Controller interface {
	// SetEndpoints takes `e` and sets one or many endpoints.
	SetEndpoints(e *echo.Echo)
	// SetVersionedEndpoints takes `g` and sets one or many endpoints.
	//
	// The `g` argument MUST have the major version of the system as path prefix.
	SetVersionedEndpoints(g *echo.Group)
}

Controller is a transport component exposing a set of endpoints through the HTTP protocol to give access to external system clients.

type Error

type Error struct {
	Kind         string            `json:"kind" xml:"kind"`
	Code         int               `json:"code" xml:"code"`
	InternalCode string            `json:"internal_code" xml:"internal_code"`
	Message      string            `json:"message" xml:"message"`
	Metadata     map[string]string `json:"metadata" xml:"-"`
}

Error is an informational structure specifying a system failure with a standard format for HTTP APIs.

NOTE: If using XML, Metadata cannot be parsed and therefore, it is ignored.

type Errors

type Errors struct {
	// Code Top level status code.
	Code int `json:"code" xml:"code"`
	// Errors slice of [Error].
	Errors []Error `json:"errors" xml:"errors"`
}

Errors is a sentinel structure containing a slice of Error.

Holds a Code property acting as top level status code.

type ServerOption

type ServerOption func(options *serverOptions)

ServerOption is a function that modifies the server behaviors.

func WithServerErrorResponseCodec

func WithServerErrorResponseCodec(format string) ServerOption

WithServerErrorResponseCodec sets the codec for error responses.

type TransactionalOption

type TransactionalOption func(*transactionalOptions)

TransactionalOption is a functional option type for configuring the Transactional middleware.

func WithTxFactory

func WithTxFactory(factory persistence.TxFactory) TransactionalOption

WithTxFactory allows to set a custom transaction factory for the Transactional middleware.

This will cause the middleware to use the provided factory instead of using a persistence.TxManager.

func WithTxManager

func WithTxManager(manager *persistence.TxManager) TransactionalOption

WithTxManager allows to set a custom transaction manager for the Transactional middleware. This will cause the middleware to run HTTP requests within transactions managed by the provided manager.

Jump to

Keyboard shortcuts

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