handlers

package
v0.11.10 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeadersMap = "headersMap"
	FinalPath  = "finalPath"
)
View Source
const (
	DEFAULT_PAGE_TEXT    = "page"
	DEFAULT_SIZE_TEXT    = "size"
	DEFAULT_PAGE         = "1"
	DEFAULT_PAGE_SIZE    = "10"
	DEFAULT_MIN_PAGESIZE = 10
	DEFAULT_MAX_PAGESIZE = 100
)
View Source
const (
	Asc = "asc"
	Dsc = "desc"
)

Variables

This section is empty.

Functions

func BaseHandler

func BaseHandler[Req any, Resp any, Handler HandlerInterface[Req, Resp]](
	core requestCore.RequestCoreInterface,
	handler Handler,
	simulation bool,
	args ...any,
) any

func CallApi added in v0.9.7

func CallApiInternal added in v0.10.3

func CallApiInternal[Resp any](
	w webFramework.WebFramework,
	core requestCore.RequestCoreInterface,
	method string,
	param libCallApi.CallParam) (*Resp, response.ErrorState)

func CallApiJSON added in v0.9.52

func CallApiNoLog added in v0.9.24

func CallApiNoLog[Resp any](
	method string,
	param libCallApi.CallParam) (*Resp, error)

func CallApiWithReceipt added in v0.9.46

func CallApiWithReceipt[Resp any](
	w webFramework.WebFramework,
	core requestCore.RequestCoreInterface,
	method string,
	param libCallApi.CallParam) (*Resp, *response.Receipt, response.ErrorState)

func CallHandler added in v0.9.7

func CallHandler[Req any, Resp any](
	title, path, api, method, query string, isJson bool,
	hasInitializer bool,
	headers []string,
	core requestCore.RequestCoreInterface,
) any

func CallRemote added in v0.9.7

func CallRemote[Req any, Resp any](
	title, path, api, method string, hasQuery, isJson bool,
	hasInitializer bool,
	transmitter func(
		path, api, method string,
		requestByte []byte,
		headers map[string]string,
		parseRemoteResp func([]byte, string, int) (int, map[string]string, any, error),
		consumer func([]byte, string, string, string, string, map[string]string) ([]byte, string, int, error),
	) (int, map[string]string, any, error),
	core requestCore.RequestCoreInterface,
	simulation bool,
	args ...string,
) any

func CallRemoteWithRespParser added in v0.9.7

func CallRemoteWithRespParser[Req any, Resp any](
	title, path, api, method string, hasQuery, isJson, forwardAuth bool,
	hasInitializer bool,
	transmitter func(
		path, api, method string,
		requestByte []byte,
		headers map[string]string,
		parseRemoteResp func([]byte, string, int) (int, map[string]string, any, error),
		consumer func([]byte, string, string, string, string, map[string]string) ([]byte, string, int, error),
	) (int, map[string]string, any, error),
	core requestCore.RequestCoreInterface,
	parseRemoteResp func([]byte, string, int) (int, map[string]string, any, error),
	simulation bool,
	args ...string,
) any

func ConsumeHandler added in v0.9.52

func ConsumeHandler[Req any, Resp libCallApi.ApiResp](
	core requestCore.RequestCoreInterface,
	params *ConsumeHandlerType[Req, Resp],
	simulation bool,
) any

func ConsumeRemoteGet added in v0.9.7

func ConsumeRemoteGet[Result any](
	w webFramework.WebFramework,
	api, url string,
	core requestCore.RequestCoreInterface,
	args ...any) (*Result, response.ErrorState)

func ConsumeRemoteGetApi added in v0.9.7

func ConsumeRemoteGetApi[Result any](
	api, url string,
	core requestCore.RequestCoreInterface,
	args ...any) any

func ConsumeRemotePost added in v0.9.7

func ConsumeRemotePost(
	w webFramework.WebFramework,
	reqLog libRequest.RequestPtr,
	request any,
	method, methodName, api, url string,
	parseRemoteResp func([]byte, string, int) (int, map[string]string, any, error),
	consumeHandler func([]byte, string, string, string, string, map[string]string) ([]byte, string, int, error),
) (int, string, any, error)

func Default added in v0.10.29

func Default() gin.HandlerFunc

Create a new pagination middleware with default values

func DefaultHeaders added in v0.9.7

func DefaultHeaders() []string

func DefaultLocals added in v0.9.7

func DefaultLocals() []string

func Dml

func Dml[Req libQuery.DmlModel](
	title, key string,
	core requestCore.RequestCoreInterface,
) any

func DmlHandler

func DmlHandler[Req libQuery.DmlModel](
	title, key, path string,
	core requestCore.RequestCoreInterface,
	mode libRequest.Type,
	validateHeader bool,
	simulation bool,
	recoveryHandler func(any),
) any

func DmlHandlerOld added in v0.9.2

func DmlHandlerOld[Req libQuery.DmlModel](
	title, key string,
	core requestCore.RequestCoreInterface,
	mode libRequest.Type,
	validateHeader bool,
) any

func ExtractHeaders added in v0.10.3

func ExtractHeaders(w webFramework.WebFramework, headers, locals []string) map[string]string

func ExtractValue added in v0.10.3

func ExtractValue(name string, source func(string) string, dest map[string]string)

func Filterate added in v0.11.2

func Filterate[Row any](paginationData libRequest.PaginationData, data []Row, filterFunc func(Filter) func(Row) bool) []Row

func FinalizeDML

func FinalizeDML(request libQuery.DmlModel, key, title string, w webFramework.WebFramework, core requestCore.RequestCoreInterface)

func InitPostRequest added in v0.9.7

func InitPostRequest(
	w webFramework.WebFramework,
	reqLog libRequest.RequestPtr,
	method, url string,
	checkDuplicate func(libRequest.Request) error,
	addEvent func(webFramework.WebFramework, string, string, string, libRequest.RequestPtr),
	insertRequest func(libRequest.Request) error,
	args ...any,
) (int, map[string]string, error)

initializer func(c webFramework.WebFramework, method, url string, reqLog libRequest.RequestPtr, args ...any) (int, map[string]string, error),

func New added in v0.10.29

func New(pageText, sizeText, defaultPage, defaultPageSize string, minPageSize, maxPageSize int) gin.HandlerFunc

Create a new pagniation middleware with custom values

func Paginate added in v0.11.0

func Paginate[Row any](paginationData libRequest.PaginationData, data []Row, less func(string) func(i int, j int) bool) []Row

func Query added in v0.11.6

func Query[Row, Resp any](
	core requestCore.RequestCoreInterface,
	handler QueryHandlerType[Row, Resp],
	simulation bool,
) any

func QueryHandler added in v0.9.20

func QueryHandler[Row any, Resp []Row](
	title, key, path string, queryMap map[string]libQuery.QueryCommand,
	core requestCore.RequestCoreInterface,
	mode libRequest.Type,
	validateHeader, simulation bool,
	recoveryHandler func(any),
) any

func QueryHandlerWithCaching added in v0.11.4

func QueryHandlerWithCaching[Row any, Resp []Row](
	title, key, path string, queryMap map[string]libQuery.QueryCommand,
	core requestCore.RequestCoreInterface,
	mode libRequest.Type,
	validateHeader, simulation bool,
	recoveryHandler func(any),
	caching *CachingArgs,
) any

func QueryHandlerWithTransform added in v0.10.25

func QueryHandlerWithTransform[Row, Resp any](
	title, key, path string, queryMap map[string]libQuery.QueryCommand,
	core requestCore.RequestCoreInterface,
	mode libRequest.Type,
	validateHeader, simulation bool,
	recoveryHandler func(any),
	replacer CommandReplacer[libRequest.PaginationData],
	translator RowTranslator[Row, Resp],
	caching *CachingArgs,
) any

Types

type CachingArgs added in v0.11.4

type CachingArgs struct {
	Cache       bool
	CacheMaxAge time.Duration
}

type CallArgs added in v0.9.7

type CallArgs[Req any, Resp any] struct {
	Title, Path, Api, Method string
	HasQuery, IsJson         bool
	HasInitializer           bool
	ForwardAuth              bool
	Transmitter              func(
		path, api, method string,
		requestByte []byte,
		headers map[string]string,
		parseRemoteResp func([]byte, string, int) (int, map[string]string, any, error),
		consumer func([]byte, string, string, string, string, map[string]string) ([]byte, string, int, error),
	) (int, map[string]string, any, error)
	Args, Locals, Headers []string
	Parser                func(respBytes []byte, desc string, status int) (int, map[string]string, any, error)
	RecoveryHandler       func(any)
}

func (CallArgs[Req, Resp]) Finalizer added in v0.9.7

func (c CallArgs[Req, Resp]) Finalizer(req HandlerRequest[Req, Resp])

func (CallArgs[Req, Resp]) Handler added in v0.9.7

func (c CallArgs[Req, Resp]) Handler(req HandlerRequest[Req, Resp]) (Resp, response.ErrorState)

func (CallArgs[Req, Resp]) Initializer added in v0.9.7

func (c CallArgs[Req, Resp]) Initializer(req HandlerRequest[Req, Resp]) response.ErrorState

func (CallArgs[Req, Resp]) Parameters added in v0.9.7

func (c CallArgs[Req, Resp]) Parameters() HandlerParameters

func (CallArgs[Req, Resp]) Simulation added in v0.9.19

func (c CallArgs[Req, Resp]) Simulation(req HandlerRequest[Req, Resp]) (Resp, response.ErrorState)

type CommandReplacer added in v0.10.29

type CommandReplacer[T any] struct {
	Token   string
	Builder func(T) string
}

func (CommandReplacer[T]) Replace added in v0.10.29

func (c CommandReplacer[T]) Replace(command string, data T) string

type ConsumeHandlerType added in v0.9.52

type ConsumeHandlerType[Req any, Resp libCallApi.ApiResp] struct {
	Title           string
	Params          libCallApi.RemoteCallParamData[Req]
	Path            string
	Mode            libRequest.Type
	VerifyHeader    bool
	SaveToRequest   bool
	HasReceipt      bool
	Headers         []string
	Api             string
	Method          string
	Query           string
	RecoveryHandler func(any)
}

func (*ConsumeHandlerType[Req, Resp]) Finalizer added in v0.9.52

func (h *ConsumeHandlerType[Req, Resp]) Finalizer(req HandlerRequest[Req, Resp])

func (*ConsumeHandlerType[Req, Resp]) Handler added in v0.9.52

func (h *ConsumeHandlerType[Req, Resp]) Handler(req HandlerRequest[Req, Resp]) (Resp, response.ErrorState)

func (*ConsumeHandlerType[Req, Resp]) Initializer added in v0.9.52

func (h *ConsumeHandlerType[Req, Resp]) Initializer(req HandlerRequest[Req, Resp]) response.ErrorState

func (*ConsumeHandlerType[Req, Resp]) Parameters added in v0.9.52

func (h *ConsumeHandlerType[Req, Resp]) Parameters() HandlerParameters

func (*ConsumeHandlerType[Req, Resp]) Simulation added in v0.9.52

func (h *ConsumeHandlerType[Req, Resp]) Simulation(req HandlerRequest[Req, Resp]) (Resp, response.ErrorState)

type DmlHandlerType

type DmlHandlerType[Req libQuery.DmlModel, Resp map[string]any] struct {
	Title           string
	Path            string
	Mode            libRequest.Type
	VerifyHeader    bool
	Key             string
	RecoveryHandler func(any)
}

func (DmlHandlerType[Req, Resp]) Finalizer

func (h DmlHandlerType[Req, Resp]) Finalizer(req HandlerRequest[Req, Resp])

func (DmlHandlerType[Req, Resp]) Handler

func (h DmlHandlerType[Req, Resp]) Handler(req HandlerRequest[Req, Resp]) (Resp, response.ErrorState)

func (DmlHandlerType[Req, Resp]) Initializer

func (h DmlHandlerType[Req, Resp]) Initializer(req HandlerRequest[Req, Resp]) response.ErrorState

func (DmlHandlerType[Req, Resp]) Parameters

func (h DmlHandlerType[Req, Resp]) Parameters() HandlerParameters

func (DmlHandlerType[Req, Resp]) Simulation added in v0.9.19

func (h DmlHandlerType[Req, Resp]) Simulation(req HandlerRequest[Req, Resp]) (Resp, response.ErrorState)

type Filter added in v0.11.2

type Filter struct {
	Field    string
	Operator string
	Value    string
}

type HandlerInterface

type HandlerInterface[Req any, Resp any] interface {
	// returns handler title
	//   Request Bodymode
	//   and validate header option
	//   and save to request table option
	//   and url path of handler
	Parameters() HandlerParameters
	// runs after validating request
	Initializer(req HandlerRequest[Req, Resp]) response.ErrorState
	// main handler runs after initialize
	Handler(req HandlerRequest[Req, Resp]) (Resp, response.ErrorState)
	// runs after sending back response
	Finalizer(req HandlerRequest[Req, Resp])
	// handles simulation mode
	Simulation(req HandlerRequest[Req, Resp]) (Resp, response.ErrorState)
}

type HandlerParameters added in v0.9.45

type HandlerParameters struct {
	Title           string
	Body            libRequest.Type
	ValidateHeader  bool
	SaveToRequest   bool
	Path            string
	HasReceipt      bool
	RecoveryHandler func(any)
	FileResponse    bool
}

type HandlerRequest

type HandlerRequest[Req any, Resp any] struct {
	Title    string
	Core     requestCore.RequestCoreInterface
	Header   *libRequest.RequestHeader
	Request  *Req
	Response Resp
	W        webFramework.WebFramework
	Args     []any
	RespSent bool
}

type QueryAllTransformer added in v0.10.25

type QueryAllTransformer[Row any, Resp []Row] struct {
}

func (QueryAllTransformer[Row, Resp]) Translate added in v0.10.25

func (s QueryAllTransformer[Row, Resp]) Translate(rows []Row, req HandlerRequest[Row, Resp]) (QueryResp[Resp], response.ErrorState)

func (QueryAllTransformer[Row, Resp]) TranslateWithPaginate added in v0.11.0

func (s QueryAllTransformer[Row, Resp]) TranslateWithPaginate(rows []Row, req HandlerRequest[Row, Resp], pd libRequest.PaginationData) (QueryResp[Resp], response.ErrorState)

type QueryHandlerType added in v0.9.20

type QueryHandlerType[Row, Resp any] struct {
	Title           string
	Path            string
	Mode            libRequest.Type
	VerifyHeader    bool
	Key             string
	Command         libQuery.QueryCommand
	Translator      RowTranslator[Row, Resp]
	RecoveryHandler func(any)
	PaginateCommand func(string, libRequest.PaginationData) string
	Cache           bool
	CacheTime       time.Time
	CacheMaxAge     time.Duration
	CacheData       map[string]Resp
	OnEmpty200      bool
}

func (QueryHandlerType[Row, Resp]) CacheKey added in v0.11.3

func (q QueryHandlerType[Row, Resp]) CacheKey(args []any) string

func (QueryHandlerType[Row, Resp]) CacheResult added in v0.11.3

func (q QueryHandlerType[Row, Resp]) CacheResult(args []any, resp Resp)

func (QueryHandlerType[Row, Resp]) CheckCache added in v0.11.3

func (q QueryHandlerType[Row, Resp]) CheckCache(args []any) *Resp

func (QueryHandlerType[Req, Resp]) Finalizer added in v0.9.20

func (q QueryHandlerType[Req, Resp]) Finalizer(req HandlerRequest[Req, Resp])

func (QueryHandlerType[Row, Resp]) Handler added in v0.9.20

func (q QueryHandlerType[Row, Resp]) Handler(req HandlerRequest[Row, Resp]) (Resp, response.ErrorState)

func (QueryHandlerType[Row, Resp]) Initializer added in v0.9.20

func (q QueryHandlerType[Row, Resp]) Initializer(req HandlerRequest[Row, Resp]) response.ErrorState

func (QueryHandlerType[Row, Resp]) Parameters added in v0.9.20

func (q QueryHandlerType[Row, Resp]) Parameters() HandlerParameters

func (QueryHandlerType[Req, Resp]) Simulation added in v0.9.20

func (q QueryHandlerType[Req, Resp]) Simulation(req HandlerRequest[Req, Resp]) (Resp, response.ErrorState)

type QueryResp added in v0.10.28

type QueryResp[Resp any] struct {
	TotalRows int
	Resp      Resp
}

type QuerySingleTransformer added in v0.10.25

type QuerySingleTransformer[Row any, Resp []Row] struct {
}

func (QuerySingleTransformer[Row, Resp]) Translate added in v0.10.25

func (s QuerySingleTransformer[Row, Resp]) Translate(rows []Row, req HandlerRequest[Row, Resp]) (QueryResp[Resp], response.ErrorState)

func (QuerySingleTransformer[Row, Resp]) TranslateWithPaginate added in v0.11.0

func (s QuerySingleTransformer[Row, Resp]) TranslateWithPaginate(rows []Row, req HandlerRequest[Row, Resp], pd libRequest.PaginationData) (QueryResp[Resp], response.ErrorState)

type RowPaginator added in v0.11.0

type RowPaginator[Row any] struct {
	Less func(libRequest.PaginationData) func(i, j int) bool
}

type RowTranslator added in v0.10.25

type RowTranslator[Row, Resp any] interface {
	Translate([]Row, HandlerRequest[Row, Resp]) (QueryResp[Resp], response.ErrorState)
	TranslateWithPaginate([]Row, HandlerRequest[Row, Resp], libRequest.PaginationData) (QueryResp[Resp], response.ErrorState)
}

type WsResponse added in v0.9.7

type WsResponse[Result any] struct {
	HttpStatus   int                      `json:"-"`
	HttpHeaders  map[string]string        `json:"-"`
	Status       int                      `json:"status"`
	Description  string                   `json:"description"`
	Result       Result                   `json:"result,omitempty"`
	ErrorData    []response.ErrorResponse `json:"errors,omitempty"`
	PrintReceipt *response.Receipt        `json:"printReceipt,omitempty"`
}

func (*WsResponse[any]) SetHeaders added in v0.9.57

func (w *WsResponse[any]) SetHeaders(headers map[string]string)

func (*WsResponse[any]) SetStatus added in v0.9.57

func (w *WsResponse[any]) SetStatus(status int)

Jump to

Keyboard shortcuts

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