requestCore

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2023 License: GPL-3.0 Imports: 22 Imported by: 0

README

requestCore

Library for handling restful requests

Documentation

Index

Constants

View Source
const RegexPaddedIp string = `^((25[0-5]|2[0-4]\d|1\d\d|0\d\d)\.?\b){4}$` //^((25[0-5]|2[0-4]\d|1\d\d|0\d\d)\.?\b){4}$

Variables

View Source
var Validate *validator.Validate

Functions

func CallApi added in v0.3.16

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

func CallRemote

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

func CallRemoteWithRespParser

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 RequestCoreInterface,
	parseRemoteResp func([]byte, string, int) (int, map[string]string, any, error),
	args ...string,
) any

func ConsumeRemoteGet

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

func ConsumeRemoteGetApi

func ConsumeRemoteGetApi(
	api, url string,
	core RequestCoreInterface,
	args ...any) any

func ConsumeRemotePost

func ConsumeRemotePost(c any, reqLog *libRequest.Request, 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),
	args ...any) (int, string, any, error)

func DeleteHandler

func DeleteHandler[Req libQuery.RecordData](title, delete, checkQuery string,
	core RequestCoreInterface,
	hasInitializer bool, parser libQuery.FieldParser,
) any

func GetAll

func GetAll[Model GetHandler](title string,
	core RequestCoreInterface,
	respHandler response.ResponseHandler,
	args ...any) any

func GetAllMapHandler

func GetAllMapHandler[Model MapHandler](title string,
	core RequestCoreInterface,
	respHandler response.ResponseHandler,
	args ...any) any

func GetMapBySubHandler

func GetMapBySubHandler[Req any, Resp libQuery.RecordData](title, sql string,
	core RequestCoreInterface,
	hasParam bool) any

func GetMapHandler

func GetMapHandler[Req any, Resp libQuery.RecordData](title, sql string,
	core RequestCoreInterface,
	hasParam bool) any

func GetPage

func GetPage[Model GetPageHandler](title string,
	core RequestCoreInterface,
	respHandler response.ResponseHandler,
	args ...any) any

func GetQuery

func GetQuery[Req any](title, sql string,
	core RequestCoreInterface,
	hasParam bool) any

func GetQueryFillable

func GetQueryFillable[Resp libQuery.QueryWithDeps](
	title, query string,
	core RequestCoreInterface,
	args ...string,
) any

func GetQueryHandler

func GetQueryHandler[Req, Resp any](title, sql string,
	core RequestCoreInterface,
	args ...any) any

func GetQueryMap

func GetQueryMap[Req any](title, sql string,
	core RequestCoreInterface,
	hasParam bool) any

func GetSingleRecord

func GetSingleRecord[Model GetHandler](title string,
	core RequestCoreInterface,
	respHandler response.ResponseHandler,
	args ...any) any

func GetSingleRecordHandler

func GetSingleRecordHandler[Req, Resp any](title, sql string,
	core RequestCoreInterface,
) any

func Init

func Init() (ut.Translator, *validator.Validate, error)

func InitPostRequest

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

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

func InitReqLog added in v0.3.18

func InitReqLog(w webFramework.WebFramework, reqLog *libRequest.Request, core RequestCoreInterface, method, path string) *response.ErrorState

func PaddedIpValidator

func PaddedIpValidator(fl validator.FieldLevel) bool

func PostHandler

func PostHandler[Req libQuery.RecordDataDml](title string,
	core RequestCoreInterface,
	hasInitializer bool,
	finalizer func(request Req, c any),
	args ...any,
) any

func PutHandler

func PutHandler[Req libQuery.RecordDataDml](title string,
	core RequestCoreInterface,
	hasInitializer bool,
	finalizer func(request Req, c any),
	args ...any,
) any

func UpdateHandler

func UpdateHandler[Req libQuery.Updatable](title string, hasReqLog bool,
	core RequestCoreInterface,
	hasInitializer bool,
	finalizer func(request Req, c any),
	args ...string,
) any

Types

type Empty

type Empty struct {
}

type GetHandler

type GetHandler interface {
	GetSingle(
		core RequestCoreInterface,
	) (any, string, error)
	GetAll(
		core RequestCoreInterface,
	) (any, string, error)
}

type GetPageHandler

type GetPageHandler interface {
	GetPage(
		core RequestCoreInterface,
		pageSize, pageId int,
	) (any, string, error)
	GetPageParams() (int, int)
}

type MapHandler

type MapHandler interface {
	GetAllMap(
		core RequestCoreInterface,
	) (map[string]any, string, error)
}

type RequestCoreInterface

type RequestCoreInterface interface {
	GetDB() libQuery.QueryRunnerInterface
	RequestTools() libRequest.RequestInterface
	Consumer() libCallApi.CallApiInterface
	Responder() response.ResponseHandler
	Dictionary() libDictionary.DictionaryInterface
}

type RequestCoreModel

type RequestCoreModel struct {
	RequestInterface   libRequest.RequestInterface
	QueryInterface     libQuery.QueryRunnerInterface
	RemoteApiInterface libCallApi.CallApiInterface
	RespHandler        response.ResponseHandler
	Dict               libDictionary.DictionaryInterface
}

func (RequestCoreModel) Consumer

func (RequestCoreModel) Dictionary

func (RequestCoreModel) GetDB

func (RequestCoreModel) RequestTools

func (m RequestCoreModel) RequestTools() libRequest.RequestInterface

func (RequestCoreModel) Responder

type WsResponse added in v0.3.16

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