axmiddleware

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 5 Imported by: 0

README

AxMiddleware Processor


type Request struct {
    Value int
}

type Response struct {
    Result int
}

func main() {
    proc := NewProcessor[*Request, *Response]().WithLogger(log.Logger).WithMiddlewares(SumMiddleware, LogMiddleware).WithHandlers(func(ctx *Context[*Request, *Response]) {
        log.Debug().Msgf("result: %d", ctx.Response().Result)
    }).Build()

    var response Response
    proc.Process(nil, &Request{Value: 10}, &response)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CatchPanicMiddlewares

func CatchPanicMiddlewares[R, S any](ctx *Context[R, S])

func LogRequestResponseMiddlewares

func LogRequestResponseMiddlewares[R, S any](ctx *Context[R, S])

Types

type Context

type Context[R, S any] struct {
	// contains filtered or unexported fields
}

func (*Context[R, S]) Abort

func (c *Context[R, S]) Abort()

func (*Context[R, S]) AbortWithError

func (c *Context[R, S]) AbortWithError(err error)

func (*Context[R, S]) AbortWithErrorAndCode

func (c *Context[R, S]) AbortWithErrorAndCode(code int, err error)

func (*Context[R, S]) Context

func (c *Context[R, S]) Context() context.Context

func (*Context[R, S]) Error

func (c *Context[R, S]) Error(err error)

func (*Context[R, S]) GetError

func (c *Context[R, S]) GetError() error

func (*Context[R, S]) IsAborted

func (c *Context[R, S]) IsAborted() bool

func (*Context[R, S]) Logger

func (c *Context[R, S]) Logger() *zerolog.Logger

func (*Context[R, S]) MustBoolValue

func (c *Context[R, S]) MustBoolValue(key interface{}) bool

func (*Context[R, S]) MustFloat64Value

func (c *Context[R, S]) MustFloat64Value(key interface{}) float64

func (*Context[R, S]) MustInt64Value

func (c *Context[R, S]) MustInt64Value(key interface{}) int64

func (*Context[R, S]) MustIntValue

func (c *Context[R, S]) MustIntValue(key interface{}) int

func (*Context[R, S]) MustStringValue

func (c *Context[R, S]) MustStringValue(key interface{}) string

func (*Context[R, S]) MustStringValueSlice

func (c *Context[R, S]) MustStringValueSlice(key interface{}) []string

func (*Context[R, S]) MustUint64Value

func (c *Context[R, S]) MustUint64Value(key interface{}) uint64

func (*Context[R, S]) MustValue

func (c *Context[R, S]) MustValue(key interface{}) interface{}

func (*Context[R, S]) Next

func (c *Context[R, S]) Next()

func (*Context[R, Q]) Request

func (c *Context[R, Q]) Request() R

func (*Context[P, S]) Response

func (c *Context[P, S]) Response() S

func (*Context[R, S]) StatusCode

func (c *Context[R, S]) StatusCode() int

func (*Context[R, S]) Value

func (c *Context[R, S]) Value(key interface{}) interface{}

func (*Context[R, S]) WithValue

func (c *Context[R, S]) WithValue(key, val interface{}) *Context[R, S]

type ContextProcessorBuilder

type ContextProcessorBuilder[R, S any] struct {
	// contains filtered or unexported fields
}

func NewProcessor

func NewProcessor[R, S any]() *ContextProcessorBuilder[R, S]

func (*ContextProcessorBuilder[R, S]) Build

func (b *ContextProcessorBuilder[R, S]) Build() MiddlewareProcessor[R, S]

func (*ContextProcessorBuilder[R, S]) WithContext

func (b *ContextProcessorBuilder[R, S]) WithContext(ctx context.Context) *ContextProcessorBuilder[R, S]

func (*ContextProcessorBuilder[R, S]) WithHandlers

func (b *ContextProcessorBuilder[R, S]) WithHandlers(handlers ...HandlerFunc[R, S]) *ContextProcessorBuilder[R, S]

func (*ContextProcessorBuilder[R, S]) WithLogger

func (b *ContextProcessorBuilder[R, S]) WithLogger(logger zerolog.Logger) *ContextProcessorBuilder[R, S]

func (*ContextProcessorBuilder[R, S]) WithMiddlewares

func (b *ContextProcessorBuilder[R, S]) WithMiddlewares(middlewares ...HandlerFunc[R, S]) *ContextProcessorBuilder[R, S]

type HandlerFunc

type HandlerFunc[R, S any] func(*Context[R, S])

type HandlersChain

type HandlersChain[R, S any] []HandlerFunc[R, S]

type MiddlewareProcessor

type MiddlewareProcessor[R, S any] interface {
	Process(ctx context.Context, request R, response S)
}

Jump to

Keyboard shortcuts

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