handlers

package
v0.9.54 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeadersMap = "headersMap"
	FinalPath  = "finalPath"
)

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 CallApiJSON added in v0.9.52

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

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, Resp any](
	core requestCore.RequestCoreInterface,
	params *ConsumeHandlerType[Req, Resp],
	simulation bool,
) any

func ConsumeRemoteGet added in v0.9.7

func ConsumeRemoteGet(
	w webFramework.WebFramework,
	api, url string,
	core requestCore.RequestCoreInterface,
	args ...any) (int, int, string, any, bool, error)

func ConsumeRemoteGetApi added in v0.9.7

func ConsumeRemoteGetApi(
	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 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,
	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 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 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

Types

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 ConsumeHandlerType added in v0.9.52

type ConsumeHandlerType[Req any, Resp any] 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 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)
}

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 QueryHandlerType added in v0.9.20

type QueryHandlerType[Row any, Resp []Row] struct {
	Title           string
	Path            string
	Mode            libRequest.Type
	VerifyHeader    bool
	Key             string
	Command         libQuery.QueryCommand
	RecoveryHandler func(any)
}

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 WsResponse added in v0.9.7

type WsResponse[Result any] struct {
	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"`
}

Jump to

Keyboard shortcuts

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