httpserver

package
v0.0.0-...-e2a5574 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: LGPL-2.1 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendGlobalLazywares

func AppendGlobalLazywares(middlewares ...MiddlewareCreator)

func BindFormFile

func BindFormFile(echoCtx *echo.Context, cmd any) error

func BindToDynamicEntity

func BindToDynamicEntity(echoCtx *echo.Context, entitySchema *dmodel.ModelSchema) (dmodel.DynamicFields, error)

BindToDynamicEntity parses the echo request body and returns a DynamicEntity containing only the fields defined in the given ModelSchema. Minimal type correction is applied via each field's TryConvert; on conversion failure the raw parsed value is kept as-is. No validation is performed.

func CustomHttpErrorHandler

func CustomHttpErrorHandler(defaultHandler echo.HTTPErrorHandler) echo.HTTPErrorHandler

func InitSubModule

func InitSubModule() error

func ItsMeMario

func ItsMeMario[T any](me T) T

func JsonBadRequest

func JsonBadRequest(echoCtx *echo.Context, err any) error

func JsonCreated

func JsonCreated(echoCtx *echo.Context, data any) error

func JsonOk

func JsonOk(echoCtx *echo.Context, data any) error

func ServeCreate

func ServeCreate[
	THttpRequest any,
	THttpResponse RestCreateResponse,
	TSvcResultData dmodel.DynamicModelGetter,
	THttpRequestPtr dyn.DynamicModelSetterPtr[THttpRequest],
](
	action string,
	echoCtx *echo.Context,
	cmd THttpRequestPtr,
	serviceFn func(ctx corectx.Context, cmd THttpRequest) (*dyn.OpResult[TSvcResultData], error),
) (err error)

func ServeExists

func ServeExists[
	THttpRequest dyn.ExistsQueryShape,
	THttpResponse dyn.ExistsResultData,
](
	action string,
	echoCtx *echo.Context,
	serviceFn func(ctx corectx.Context, cmd THttpRequest) (*dyn.OpResult[dyn.ExistsResultData], error),
) (err error)

func ServeGeneralMutate

func ServeGeneralMutate[
	THttpRequest any,
	THttpResponse RestMutateResponse,
](
	action string,
	echoCtx *echo.Context,
	serviceFn func(ctx corectx.Context, cmd THttpRequest) (*dyn.OpResult[dyn.MutateResultData], error),
) (err error)

Use this function for mutation operations (delete, manageM2m, setIsArchived, etc.), but not for update.

func ServeGetOne

func ServeGetOne[
	TSvcQuery any,
	TDomain dmodel.DynamicModelGetter,
](
	action string,
	echoCtx *echo.Context,
	serviceFn func(ctx corectx.Context, cmd TSvcQuery) (*dyn.OpResult[TDomain], error),
) (err error)

func ServeGetOne2

func ServeGetOne2[
	THttpRequest any,
	THttpResponse RestGetOneResponse[dmodel.DynamicFields],
	TDomain dmodel.DynamicModelGetter,
](
	action string,
	echoCtx *echo.Context,
	serviceFn func(ctx corectx.Context, cmd THttpRequest) (*dyn.OpResult[dyn.SingleResultData[TDomain]], error),
) (err error)

func ServeRequest

func ServeRequest[THttpReq any, THttpResp any, TSvcCommand any, TSvcResult CmdResult](
	echoCtx *echo.Context,
	serviceFn func(ctx corecrud.Context, cmd TSvcCommand) (*TSvcResult, error),
	requestToCommandFn func(request THttpReq) TSvcCommand,
	resultToResponseFn func(result TSvcResult) THttpResp,
	jsonSuccessFn func(*echo.Context, any) error,
) error

func ServeRequest2

func ServeRequest2[THttpReq any, THttpResp any, TSvcCommand any, TSvcResultData any](
	echoCtx *echo.Context,
	serviceFn func(ctx corectx.Context, cmd TSvcCommand) (*dyn.OpResult[TSvcResultData], error),
	requestToCommandFn func(request THttpReq) TSvcCommand,
	resultToResponseFn func(resultData TSvcResultData) THttpResp,
	jsonSuccessFn func(*echo.Context, any) error,
	skipNotFoundError ...bool,
) error

func ServeRequestDynamic

func ServeRequestDynamic[THttpResp any, TSvcCommand any, TSvcResultData any](
	echoCtx *echo.Context,
	serviceFn func(ctx corectx.Context, cmd TSvcCommand) (*dyn.OpResult[TSvcResultData], error),
	requestToCommandFn func(requestFields dmodel.DynamicFields) TSvcCommand,
	resultToResponseFn func(data TSvcResultData) THttpResp,
	jsonSuccessFn func(*echo.Context, any) error,
) error

func ServeRequestFormData

func ServeRequestFormData[TBinding any, THttpResp any, TSvcCommand, TSvcResultData any](
	echoCtx *echo.Context,
	serviceFn func(ctx corectx.Context, cmd TSvcCommand) (*dyn.OpResult[TSvcResultData], error),
	requestToCommandFn func(request TBinding) TSvcCommand,
	resultToResponseFn func(resultData TSvcResultData) THttpResp,
	jsonSuccessFn func(*echo.Context, any) error,
	skipNotFoundError ...bool,
) error

func ServeSearch

func ServeSearch[
	THttpRequest any,
	THttpResponse RestSearchResponse[dmodel.DynamicFields],
	TDomain dmodel.DynamicModelGetter,
](
	action string,
	echoCtx *echo.Context,
	serviceFn func(ctx corectx.Context, cmd THttpRequest) (*dyn.OpResult[dyn.PagedResultData[TDomain]], error),
) (err error)

func ServeStreamFile

func ServeStreamFile[THttpReq FileStreamRequest, TSvcCommand any, TSvcResultData any](
	echoCtx *echo.Context,
	serviceFn func(ctx corectx.Context, cmd TSvcCommand) (*dyn.OpResult[TSvcResultData], error),
	requestToCommandFn func(req THttpReq) TSvcCommand,
	buildFileStreamResponse func(data TSvcResultData) GetFileStreamResponse,
	fallbackNameHeader string,
	skipNotFoundError ...bool,
) error

func ServeUpdate

func ServeUpdate[
	THttpRequest any,
	THttpResponse RestMutateResponse,
	THttpRequestPtr dyn.DynamicModelSetterPtr[THttpRequest],
](
	action string,
	echoCtx *echo.Context,
	cmd THttpRequestPtr,
	serviceFn func(ctx corectx.Context, cmd THttpRequest) (*dyn.OpResult[dyn.MutateResultData], error),
) (err error)

Types

type CmdResult

type CmdResult interface {
	GetClientError() *ft.ClientError
	GetHasData() bool
}

type FileStreamRequest

type FileStreamRequest interface {
	IsDownloadRequest() bool
	GetRangeHeader() string
}

type FileStreamRequestBase

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

func (FileStreamRequestBase) GetRangeHeader

func (this FileStreamRequestBase) GetRangeHeader() string

func (FileStreamRequestBase) IsDownloadRequest

func (this FileStreamRequestBase) IsDownloadRequest() bool

type GetFileStreamResponse

type GetFileStreamResponse struct {
	Name          string
	MimeType      string
	Body          io.ReadCloser
	ContentLength *int64
	ContentRange  *string
}

type HttpServer

type HttpServer struct {
	Name string

	LazyMiddlewares []*m.LazyMiddleware
	// contains filtered or unexported fields
}

func (HttpServer) Shutdown

func (this HttpServer) Shutdown()

func (*HttpServer) Start

func (this *HttpServer) Start() error

func (HttpServer) Use

func (this HttpServer) Use(middlewares ...echo.MiddlewareFunc)

func (*HttpServer) UseLazy

func (this *HttpServer) UseLazy(lazywares ...*m.LazyMiddleware)

type MiddlewareCreator

type MiddlewareCreator func() echo.MiddlewareFunc

type RestBase deprecated

type RestBase struct {
	ConfigSvc config.ConfigService
	Logger    logging.LoggerService
	CqrsBus   cqrs.CqrsBus
}

Deprecated: No longer used.

type RestCreateResponse

type RestCreateResponse struct {
	Id model.Id `json:"id"`
	// For backward compatibility. Will be removed.
	CreatedAtMs int64      `json:"createdAt,omitempty"`
	CreatedAt   string     `json:"created_at,omitempty"`
	Etag        model.Etag `json:"etag"`
}

func NewRestCreateResponseDyn

func NewRestCreateResponseDyn(fields dmodel.DynamicFields) *RestCreateResponse

func (*RestCreateResponse) FromEntity

func (this *RestCreateResponse) FromEntity(src createdEntity)

func (*RestCreateResponse) FromNonEntity

func (this *RestCreateResponse) FromNonEntity(src any)

type RestDeleteResponse deprecated

type RestDeleteResponse struct {
	Id        model.Id `json:"id"`
	DeletedAt int64    `json:"deleted_at"`
}

Deprecated: Use RestMutateResponse instead.

func (*RestDeleteResponse) FromEntity

func (this *RestDeleteResponse) FromEntity(src deletedEntity)

func (*RestDeleteResponse) FromNonEntity

func (this *RestDeleteResponse) FromNonEntity(src any)

type RestDeleteResponse2 deprecated

type RestDeleteResponse2 struct {
	AffectedCount int    `json:"affected_count"`
	AffectedAt    string `json:"affected_at"`
}

Deprecated: Use RestMutateResponse instead.

func NewRestDeleteResponse2 deprecated

func NewRestDeleteResponse2(src dyn.MutateResultData) RestDeleteResponse2

Deprecated: Use NewRestMutateResponse instead.

type RestGetOneResponse

type RestGetOneResponse[TItem any] struct {
	Item TItem              `json:"item"`
	Meta dyn.SingleMetaData `json:"meta"`
}

type RestMutateResponse

type RestMutateResponse struct {
	AffectedCount int        `json:"affected_count"`
	AffectedAt    string     `json:"affected_at"`
	Etag          model.Etag `json:"etag,omitempty"`
}

RestMutateResponse is a mutation payload without etag (e.g. junction-only updates).

func NewRestMutateResponse

func NewRestMutateResponse(src dyn.MutateResultData) RestMutateResponse

type RestSearchResponse

type RestSearchResponse[TItem any] struct {
	Items []TItem `json:"items"`
	Total int     `json:"total"`
	Page  int     `json:"page"`
	Size  int     `json:"size"`

	DesiredFields []string `json:"desired_fields"`
	MaskedFields  []string `json:"masked_fields"`
	SchemaEtag    string   `json:"schema_etag"`
}

type RestUpdateResponse

type RestUpdateResponse struct {
	Id          model.Id   `json:"id"`
	UpdatedAtMs int64      `json:"updatedAt,omitempty"`
	UpdatedAt   string     `json:"updated_at,omitempty"`
	Etag        model.Etag `json:"etag"`
}

func (*RestUpdateResponse) FromEntity

func (this *RestUpdateResponse) FromEntity(src updatedEntity)

func (*RestUpdateResponse) FromNonEntity

func (this *RestUpdateResponse) FromNonEntity(src any)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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