middleware

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package middleware provides infrastructure layer middleware adapters for integrating framework-agnostic middleware with specific HTTP frameworks.

Package middleware provides infrastructure layer middleware adapters for integrating framework-agnostic middleware with specific HTTP frameworks.

Package middleware provides infrastructure layer middleware adapters for integrating framework-agnostic middleware with specific HTTP frameworks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEchoRequest

func NewEchoRequest(c echo.Context) core.Request

NewEchoRequest creates a new Echo request wrapper.

Types

type EchoAdapter

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

EchoAdapter adapts our framework-agnostic middleware to Echo's middleware interface. This adapter follows the adapter pattern to bridge between our clean architecture and Echo's framework-specific implementation.

func NewEchoAdapter

func NewEchoAdapter(middleware core.Middleware) *EchoAdapter

NewEchoAdapter creates a new Echo adapter for the given middleware.

func (*EchoAdapter) ToEchoMiddleware

func (a *EchoAdapter) ToEchoMiddleware() echo.MiddlewareFunc

ToEchoMiddleware converts our middleware to Echo's middleware function. This method handles the conversion between our Request/Response interfaces and Echo's echo.Context, ensuring proper error handling and context management.

type EchoChainAdapter

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

EchoChainAdapter adapts our middleware chain to Echo's middleware chain.

func NewEchoChainAdapter

func NewEchoChainAdapter(chain core.Chain) *EchoChainAdapter

NewEchoChainAdapter creates a new Echo chain adapter.

func (*EchoChainAdapter) ToEchoMiddleware

func (a *EchoChainAdapter) ToEchoMiddleware() echo.MiddlewareFunc

ToEchoMiddleware converts our middleware chain to Echo's middleware function.

type EchoMiddlewareWrapper

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

EchoMiddlewareWrapper wraps Echo middleware to implement our Middleware interface.

func (*EchoMiddlewareWrapper) Name

func (w *EchoMiddlewareWrapper) Name() string

Name returns the name of this middleware wrapper.

func (*EchoMiddlewareWrapper) Priority

func (w *EchoMiddlewareWrapper) Priority() int

Priority returns the priority of this middleware wrapper.

func (*EchoMiddlewareWrapper) Process

Process implements our Middleware interface by converting to Echo middleware.

type EchoOrchestratorAdapter

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

EchoOrchestratorAdapter adapts our orchestrator to Echo's middleware system.

func NewEchoOrchestratorAdapter

func NewEchoOrchestratorAdapter(orchestrator core.Orchestrator) *EchoOrchestratorAdapter

NewEchoOrchestratorAdapter creates a new Echo orchestrator adapter.

func (*EchoOrchestratorAdapter) GetEchoChain

func (a *EchoOrchestratorAdapter) GetEchoChain(name string) (echo.MiddlewareFunc, bool)

GetEchoChain retrieves a named chain and converts it to Echo middleware.

func (*EchoOrchestratorAdapter) RegisterEchoChain

func (a *EchoOrchestratorAdapter) RegisterEchoChain(name string, chainType core.ChainType) error

RegisterEchoChain registers a named chain for use with Echo.

func (*EchoOrchestratorAdapter) SetupEchoMiddleware

func (a *EchoOrchestratorAdapter) SetupEchoMiddleware(e *echo.Echo, chainType core.ChainType) error

SetupEchoMiddleware sets up Echo middleware based on our orchestrator configuration.

type EchoRegistryAdapter

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

EchoRegistryAdapter adapts our middleware registry to Echo's middleware system.

func NewEchoRegistryAdapter

func NewEchoRegistryAdapter(registry core.Registry) *EchoRegistryAdapter

NewEchoRegistryAdapter creates a new Echo registry adapter.

func (*EchoRegistryAdapter) GetEchoMiddleware

func (a *EchoRegistryAdapter) GetEchoMiddleware(name string) (echo.MiddlewareFunc, bool)

GetEchoMiddleware retrieves middleware by name and converts it to Echo middleware.

func (*EchoRegistryAdapter) RegisterEchoMiddleware

func (a *EchoRegistryAdapter) RegisterEchoMiddleware(name string, echoMiddleware echo.MiddlewareFunc) error

RegisterEchoMiddleware registers Echo middleware with our registry.

type EchoRequest

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

EchoRequest wraps Echo's echo.Context to implement our Request interface. This adapter provides access to Echo's request data through our framework-agnostic interface.

func (*EchoRequest) Accepts

func (r *EchoRequest) Accepts(contentType string) bool

Accepts returns true if the request accepts the given content type

func (*EchoRequest) AcceptsEncoding

func (r *EchoRequest) AcceptsEncoding(encoding string) bool

AcceptsEncoding returns true if the request accepts the given encoding

func (*EchoRequest) AcceptsLanguage

func (r *EchoRequest) AcceptsLanguage(language string) bool

AcceptsLanguage returns true if the request accepts the given language

func (*EchoRequest) Body

func (r *EchoRequest) Body() io.Reader

Body returns the request body as an io.Reader

func (*EchoRequest) ContentLength

func (r *EchoRequest) ContentLength() int64

ContentLength returns the length of the request body

func (*EchoRequest) ContentType

func (r *EchoRequest) ContentType() string

ContentType returns the Content-Type header value

func (*EchoRequest) Context

func (r *EchoRequest) Context() context.Context

Context returns the request context

func (*EchoRequest) Cookie

func (r *EchoRequest) Cookie(name string) (*http.Cookie, error)

Cookie returns a cookie by name

func (*EchoRequest) Cookies

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

Cookies returns all cookies

func (*EchoRequest) Form

func (r *EchoRequest) Form() (url.Values, error)

Form returns the parsed form data

func (*EchoRequest) FormValue

func (r *EchoRequest) FormValue(name string) string

FormValue returns a form value by name

func (*EchoRequest) ForwardedFor

func (r *EchoRequest) ForwardedFor() string

ForwardedFor returns the X-Forwarded-For header value

func (*EchoRequest) Get

func (r *EchoRequest) Get(key string) any

Get retrieves a value from the request context

func (*EchoRequest) Headers

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

Headers returns the request headers

func (*EchoRequest) Host

func (r *EchoRequest) Host() string

Host returns the Host header value

func (*EchoRequest) IsAJAX

func (r *EchoRequest) IsAJAX() bool

IsAJAX returns true if the request is an AJAX request

func (*EchoRequest) IsJSON

func (r *EchoRequest) IsJSON() bool

IsJSON returns true if the request expects JSON response

func (*EchoRequest) IsSecure

func (r *EchoRequest) IsSecure() bool

IsSecure returns true if the request was made over HTTPS

func (*EchoRequest) IsWebSocket

func (r *EchoRequest) IsWebSocket() bool

IsWebSocket returns true if the request is a WebSocket upgrade request

func (*EchoRequest) IsXML

func (r *EchoRequest) IsXML() bool

IsXML returns true if the request expects XML response

func (*EchoRequest) Method

func (r *EchoRequest) Method() string

Method returns the HTTP method

func (*EchoRequest) MultipartForm

func (r *EchoRequest) MultipartForm() (*multipart.Form, error)

MultipartForm returns the parsed multipart form data

func (*EchoRequest) Param

func (r *EchoRequest) Param(name string) string

Param returns a path parameter by name

func (*EchoRequest) Params

func (r *EchoRequest) Params() map[string]string

Params returns all path parameters

func (*EchoRequest) Path

func (r *EchoRequest) Path() string

Path returns the request path

func (*EchoRequest) Query

func (r *EchoRequest) Query() map[string][]string

Query returns the query parameters

func (*EchoRequest) RealIP

func (r *EchoRequest) RealIP() string

RealIP returns the real IP address of the client

func (*EchoRequest) Referer

func (r *EchoRequest) Referer() string

Referer returns the Referer header value

func (*EchoRequest) RemoteAddr

func (r *EchoRequest) RemoteAddr() string

RemoteAddr returns the client's network address

func (*EchoRequest) RequestID

func (r *EchoRequest) RequestID() string

RequestID returns the request ID if present

func (*EchoRequest) Set

func (r *EchoRequest) Set(key string, value any)

Set stores a value in the request context

func (*EchoRequest) Timestamp

func (r *EchoRequest) Timestamp() time.Time

Timestamp returns when the request was received

func (*EchoRequest) URL

func (r *EchoRequest) URL() *http.Request

URL returns the request URL

func (*EchoRequest) UserAgent

func (r *EchoRequest) UserAgent() string

UserAgent returns the User-Agent header value

func (*EchoRequest) WithContext

func (r *EchoRequest) WithContext(ctx context.Context) core.Request

WithContext returns a new request with the given context

type EchoResponseBuilder

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

EchoResponseBuilder provides a builder pattern for creating responses that can be easily applied to Echo contexts.

func NewEchoResponseBuilder

func NewEchoResponseBuilder(c echo.Context) *EchoResponseBuilder

NewEchoResponseBuilder creates a new Echo response builder.

func (*EchoResponseBuilder) Body

Body sets the response body.

func (*EchoResponseBuilder) BodyBytes

func (b *EchoResponseBuilder) BodyBytes(data []byte) *EchoResponseBuilder

BodyBytes sets the response body as bytes.

func (*EchoResponseBuilder) BodyString

func (b *EchoResponseBuilder) BodyString(data string) *EchoResponseBuilder

BodyString sets the response body as a string.

func (*EchoResponseBuilder) Build

func (b *EchoResponseBuilder) Build() core.Response

Build returns the built response.

func (*EchoResponseBuilder) ContentType

func (b *EchoResponseBuilder) ContentType(contentType string) *EchoResponseBuilder

ContentType sets the Content-Type header.

func (*EchoResponseBuilder) Cookie

func (b *EchoResponseBuilder) Cookie(cookie *http.Cookie) *EchoResponseBuilder

Cookie adds a cookie to the response.

func (*EchoResponseBuilder) Error

func (b *EchoResponseBuilder) Error(statusCode int, err error) *EchoResponseBuilder

Error sets the response to return an error.

func (*EchoResponseBuilder) HTML

HTML sets the response to return HTML.

func (*EchoResponseBuilder) Header

func (b *EchoResponseBuilder) Header(key, value string) *EchoResponseBuilder

Header adds a header to the response.

func (*EchoResponseBuilder) Headers

func (b *EchoResponseBuilder) Headers(headers map[string]string) *EchoResponseBuilder

Headers adds multiple headers to the response.

func (*EchoResponseBuilder) JSON

JSON sets the response to return JSON data.

func (*EchoResponseBuilder) Redirect

func (b *EchoResponseBuilder) Redirect(statusCode int, url string) *EchoResponseBuilder

Redirect sets the response to redirect to the given URL.

func (*EchoResponseBuilder) RequestID

func (b *EchoResponseBuilder) RequestID(requestID string) *EchoResponseBuilder

RequestID sets the request ID for the response.

func (*EchoResponseBuilder) Send

func (b *EchoResponseBuilder) Send() error

Send applies the response to Echo and returns any error.

func (*EchoResponseBuilder) Status

func (b *EchoResponseBuilder) Status(code int) *EchoResponseBuilder

Status sets the response status code.

func (*EchoResponseBuilder) Text

Text sets the response to return plain text.

type EchoResponseConverter

type EchoResponseConverter struct{}

EchoResponseConverter provides utility functions for converting between Echo responses and our framework-agnostic responses.

func NewEchoResponseConverter

func NewEchoResponseConverter() *EchoResponseConverter

NewEchoResponseConverter creates a new Echo response converter.

func (*EchoResponseConverter) FromEchoResponse

func (c *EchoResponseConverter) FromEchoResponse(echoResp *echo.Response) core.Response

FromEchoResponse converts an Echo response to our Response interface. Note: This is a simplified conversion as Echo doesn't provide direct access to all response data in this context.

type EchoResponseWrapper

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

EchoResponseWrapper wraps our Response interface to work with Echo's response system. This adapter provides a bridge between our framework-agnostic response and Echo's response handling mechanisms.

func NewEchoResponseWrapper

func NewEchoResponseWrapper(resp core.Response, c echo.Context) *EchoResponseWrapper

NewEchoResponseWrapper creates a new Echo response wrapper.

func (*EchoResponseWrapper) ApplyToEcho

func (w *EchoResponseWrapper) ApplyToEcho() error

ApplyToEcho applies our response to Echo's context. This method handles status codes, headers, cookies, and body writing.

type EchoResponseWriter

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

EchoResponseWriter provides a writer that can be used to write responses directly to Echo contexts while maintaining our framework-agnostic interface.

func NewEchoResponseWriter

func NewEchoResponseWriter(c echo.Context) *EchoResponseWriter

NewEchoResponseWriter creates a new Echo response writer.

func (*EchoResponseWriter) Bytes

func (w *EchoResponseWriter) Bytes() []byte

Bytes returns the buffered content as bytes.

func (*EchoResponseWriter) Flush

func (w *EchoResponseWriter) Flush() error

Flush writes the buffered content to Echo's response writer.

func (*EchoResponseWriter) String

func (w *EchoResponseWriter) String() string

String returns the buffered content as a string.

func (*EchoResponseWriter) Write

func (w *EchoResponseWriter) Write(p []byte) (n int, err error)

Write implements io.Writer interface.

func (*EchoResponseWriter) WriteHTML

func (w *EchoResponseWriter) WriteHTML(html string) error

WriteHTML writes HTML to the response.

func (*EchoResponseWriter) WriteJSON

func (w *EchoResponseWriter) WriteJSON(data any) error

WriteJSON writes JSON data to the response.

func (*EchoResponseWriter) WriteString

func (w *EchoResponseWriter) WriteString(s string) (int, error)

WriteString writes a string to the response.

func (*EchoResponseWriter) WriteText

func (w *EchoResponseWriter) WriteText(text string) error

WriteText writes plain text to the response.

Jump to

Keyboard shortcuts

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