handlers

package
v0.9.9 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2023 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,
	args ...any,
) any

func CallApi added in v0.9.7

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,
	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),
	args ...string,
) 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,
) 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),

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)
}

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() (string, libRequest.Type, bool, bool, string)

type DmlHandlerType

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

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() (string, libRequest.Type, bool, bool, 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() (string, libRequest.Type, bool, bool, string)
	// 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])
}

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
}

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"`
}

Jump to

Keyboard shortcuts

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