Documentation
¶
Index ¶
Constants ¶
const ModuleName = "jsonapi"
ModuleName is the module name.
Variables ¶
var FxJSONAPIModule = fx.Module( ModuleName, fxhttpserver.AsErrorHandler(NewErrorHandler), fx.Provide(fx.Annotate(ProvideProcessor, fx.As(new(Processor)))), )
FxJSONAPIModule is the Fx JSON API module.
Functions ¶
func Marshall ¶
func Marshall(data any, params MarshallParams) ([]byte, error)
Marshall is used to marshall in json api format a given input with MarshallParams.
Types ¶
type DefaultProcessor ¶
type DefaultProcessor struct {
// contains filtered or unexported fields
}
DefaultProcessor is the default Processor implementation.
func NewDefaultProcessor ¶
func NewDefaultProcessor(config *config.Config) *DefaultProcessor
NewDefaultProcessor returns a new DefaultProcessor instance.
func ProvideProcessor ¶
func ProvideProcessor(p ProvideProcessorParam) *DefaultProcessor
ProvideProcessor provides a new DefaultProcessor instance.
func (*DefaultProcessor) ProcessRequest ¶
func (p *DefaultProcessor) ProcessRequest(c echo.Context, data any, options ...ProcessorOption) error
ProcessRequest processes a json api request.
func (*DefaultProcessor) ProcessResponse ¶
func (p *DefaultProcessor) ProcessResponse(c echo.Context, code int, data any, options ...ProcessorOption) error
ProcessResponse processes a json api response.
type ErrorHandler ¶
type ErrorHandler struct {
// contains filtered or unexported fields
}
ErrorHandler is an Echo error handler for JSON APIs.
func NewErrorHandler ¶
func NewErrorHandler(config *config.Config) *ErrorHandler
NewErrorHandler provides a new ErrorHandler instance.
func (*ErrorHandler) Handle ¶
func (h *ErrorHandler) Handle() echo.HTTPErrorHandler
Handle returns the Echo compatible echo.HTTPErrorHandler.
type MarshallParams ¶
type Processor ¶
type Processor interface { ProcessRequest(c echo.Context, data any, options ...ProcessorOption) error ProcessResponse(c echo.Context, code int, data any, options ...ProcessorOption) error }
Processor is the interface for json api processors implementations.
type ProcessorOption ¶
type ProcessorOption func(o *Options)
ProcessorOption are functional options for the Processor.
func WithIncluded ¶
func WithIncluded(i bool) ProcessorOption
WithIncluded is used to add included to the json api representation.
func WithMetadata ¶
func WithMetadata(m map[string]any) ProcessorOption
WithMetadata is used to add metadata to the json api representation.