Documentation
¶
Index ¶
- Constants
- Variables
- func BaseHandler[Req any, Resp any, Handler HandlerInterface[Req, Resp]](core requestCore.RequestCoreInterface, handler Handler, simulation bool, ...) any
- func BuildBaseRemoteHeaders(w webFramework.WebFramework, appName, correlationID string) map[string]string
- func BuildRequestURL(domain, path, query string) string
- func BuildTimeoutError(domain string, statusCode int) error
- func CallApi[Resp any](w webFramework.WebFramework, core requestCore.RequestCoreInterface, ...) (*Resp, error)
- func CallApiForm[Req any, Resp any](w webFramework.WebFramework, core requestCore.RequestCoreInterface, ...) (Resp, error)
- func CallApiInternal[Resp any](w webFramework.WebFramework, core requestCore.RequestCoreInterface, ...) (*Resp, error)
- func CallApiJSON[Req any, Resp any](w webFramework.WebFramework, core requestCore.RequestCoreInterface, ...) (Resp, error)
- func CallApiJSONWithOpts[Req any, Resp any](w webFramework.WebFramework, core requestCore.RequestCoreInterface, ...) (Resp, error)
- func CallApiNoLog[Resp any](w webFramework.WebFramework, method string, param libCallApi.CallParam) (*Resp, error)
- func CallApiWithReceipt[Resp any](w webFramework.WebFramework, core requestCore.RequestCoreInterface, ...) (*Resp, *response.Receipt, error)
- func CallRemote[Req any, Resp any](core requestCore.RequestCoreInterface, callArg CallArgs[Req, Resp], ...) any
- func CallRemoteWithRespParser[Req any, Resp any](core requestCore.RequestCoreInterface, callArgs CallArgs[Req, Resp], ...) any
- func ConsumeHandler[Req, Resp any](core requestCore.RequestCoreInterface, params *ConsumeHandlerType[Req, Resp], ...) any
- func Default() gin.HandlerFunc
- func DmlHandler[Req libQuery.DmlModel](core requestCore.RequestCoreInterface, ...) any
- func ExecDML(request libQuery.DmlModel, key, title string, w webFramework.WebFramework, ...) (map[string]any, error)
- func ExecuteDML(request libQuery.DmlModel, key, title string, w webFramework.WebFramework, ...) (map[string]any, error)
- func ExtractHeaders(w webFramework.WebFramework, headers, locals []string) map[string]string
- func ExtractValue(name string, source func(string) string, dest map[string]string)
- func Filterate[Row any](paginationData libRequest.PaginationData, data []Row, ...) []Row
- func FinalizeDML(request libQuery.DmlModel, key, title string, w webFramework.WebFramework, ...)
- func GetPersistedRecordID(w webFramework.WebFramework) (any, bool)
- func InitPostRequest(w webFramework.WebFramework, reqLog libRequest.RequestPtr, method, url string, ...) (int, map[string]string, error)
- func New(pageText, sizeText, defaultPage, defaultPageSize string, ...) gin.HandlerFunc
- func NormalizeCallError(err error) error
- func Paginate[Row any](paginationData libRequest.PaginationData, data []Row, ...) []Row
- func PreControlDML(request libQuery.DmlModel, key, title string, w webFramework.WebFramework, ...) error
- func Query[Row, Resp any](core requestCore.RequestCoreInterface, handler QueryHandlerType[Row, Resp], ...) any
- func QueryHandler[Row any, Resp []Row](title, key, path string, queryMap map[string]libQuery.QueryCommand, ...) any
- func QueryHandlerWithCaching[Row any, Resp []Row](title, key, path string, queryMap map[string]libQuery.QueryCommand, ...) any
- func QueryHandlerWithOrm[Row any, Resp []Row](title, key, path string, queryMap map[string]libQuery.QueryCommand, ...) any
- func QueryHandlerWithTransform[Row, Resp any](title, key, path string, queryMap map[string]libQuery.QueryCommand, ...) any
- func QueryWithOrm[Row, Resp any](core requestCore.RequestCoreInterface, handler OrmHandlerType[Row, Resp], ...) any
- func Recovery[Req any, Resp any, Handler HandlerInterface[Req, Resp]](start time.Time, w webFramework.WebFramework, handler Handler, ...)
- func SetPersistedRecordID(w webFramework.WebFramework, id any)
- func ShouldSkipApiCall(endpoint, method string, skipPatterns []string) bool
- type ApiCallInfo
- type CachingArgs
- type CallApiLogKeys
- type CallApiOptions
- type CallArgs
- func (c CallArgs[Req, Resp]) Finalizer(req HandlerRequest[Req, Resp])
- func (c CallArgs[Req, Resp]) Handler(req HandlerRequest[Req, Resp]) (Resp, error)
- func (c CallArgs[Req, Resp]) Initializer(req HandlerRequest[Req, Resp]) error
- func (c CallArgs[Req, Resp]) Parameters() HandlerParameters[Req, Resp]
- func (c CallArgs[Req, Resp]) Simulation(req HandlerRequest[Req, Resp]) (Resp, error)
- type CommandReplacer
- type ConsumeHandlerType
- func (h *ConsumeHandlerType[Req, Resp]) Finalizer(req HandlerRequest[Req, Resp])
- func (h *ConsumeHandlerType[Req, Resp]) Handler(req HandlerRequest[Req, Resp]) (Resp, error)
- func (h *ConsumeHandlerType[Req, Resp]) Initializer(req HandlerRequest[Req, Resp]) error
- func (h *ConsumeHandlerType[Req, Resp]) Parameters() HandlerParameters[Req, Resp]
- func (h *ConsumeHandlerType[Req, Resp]) Simulation(req HandlerRequest[Req, Resp]) (Resp, error)
- type DmlHandlerType
- func (h DmlHandlerType[Req, Resp]) Finalizer(req HandlerRequest[Req, Resp])
- func (h DmlHandlerType[Req, Resp]) Handler(req HandlerRequest[Req, Resp]) (Resp, error)
- func (h DmlHandlerType[Req, Resp]) Initializer(req HandlerRequest[Req, Resp]) error
- func (h DmlHandlerType[Req, Resp]) Parameters() HandlerParameters[Req, Resp]
- func (h DmlHandlerType[Req, Resp]) Simulation(req HandlerRequest[Req, Resp]) (Resp, error)
- type Filter
- type FuncPersister
- type HandlerInterface
- type HandlerOutcome
- type HandlerParameters
- type HandlerRequest
- func (hr *HandlerRequest[Req, Resp]) AddSpanAttribute(key, value string)
- func (hr *HandlerRequest[Req, Resp]) AddSpanAttributes(attrs map[string]string)
- func (hr *HandlerRequest[Req, Resp]) AddSpanEvent(name string, attrs map[string]string)
- func (hr HandlerRequest[Req, Resp]) GetParser() webFramework.RequestParser
- func (hr *HandlerRequest[Req, Resp]) RecordSpanError(err error, attrs map[string]string)
- func (trx *HandlerRequest[Req, Resp]) SetOutcome(err error, httpStatus int)
- func (hr *HandlerRequest[Req, Resp]) StartChildSpan(name string, attrs map[string]string) (context.Context, trace.Span)
- type OrmHandlerType
- func (q OrmHandlerType[Row, Resp]) CacheKey(args []any) string
- func (q OrmHandlerType[Row, Resp]) CacheResult(args []any, rows []Row)
- func (q OrmHandlerType[Row, Resp]) CheckCache(args []any) []Row
- func (q OrmHandlerType[Req, Resp]) Finalizer(req HandlerRequest[Req, Resp])
- func (q OrmHandlerType[Row, Resp]) Handler(req HandlerRequest[Row, Resp]) (Resp, error)
- func (q OrmHandlerType[Row, Resp]) Initializer(req HandlerRequest[Row, Resp]) error
- func (q OrmHandlerType[Row, Resp]) Parameters() HandlerParameters[Row, Resp]
- func (q OrmHandlerType[Req, Resp]) Simulation(req HandlerRequest[Req, Resp]) (Resp, error)
- type QueryAllTransformer
- type QueryHandlerType
- func (q QueryHandlerType[Row, Resp]) CacheKey(args []any) string
- func (q QueryHandlerType[Row, Resp]) CacheResult(args []any, rows []Row)
- func (q QueryHandlerType[Row, Resp]) CheckCache(args []any) []Row
- func (q QueryHandlerType[Req, Resp]) Finalizer(req HandlerRequest[Req, Resp])
- func (q QueryHandlerType[Row, Resp]) Handler(req HandlerRequest[Row, Resp]) (Resp, error)
- func (q QueryHandlerType[Row, Resp]) Initializer(req HandlerRequest[Row, Resp]) error
- func (q QueryHandlerType[Row, Resp]) Parameters() HandlerParameters[Row, Resp]
- func (q QueryHandlerType[Req, Resp]) Simulation(req HandlerRequest[Req, Resp]) (Resp, error)
- type QueryResp
- type QuerySingleTransformer
- type RequestPersister
- type RowPaginator
- type RowTranslator
- type WsResponse
Constants ¶
const ( HeadersMap = "headersMap" FinalPath = "finalPath" )
const ( DEFAULT_PAGE_TEXT = "page" DEFAULT_SIZE_TEXT = "size" DEFAULT_PAGE = "1" DEFAULT_PAGE_SIZE = "10" DEFAULT_MIN_PAGESIZE = 10 DEFAULT_MAX_PAGESIZE = 100 )
const ( Asc = "asc" Dsc = "desc" )
const (
CallApiLogEntry string = "ApiCall"
)
const CorrelationIDHeader = "X-Correlation-ID"
CorrelationIDHeader is the HTTP header name used to propagate the correlation ID to downstream services.
const CorrelationIDLocalKey = "correlation_id"
CorrelationIDLocalKey is the per-request local-storage key for the correlation ID, an alternative cross-service correlation identifier to the request ID. Set it during request initialization via w.Parser.SetLocal(CorrelationIDLocalKey, correlationID).
const PersistedRecordIDKey = "handlers.persisted_record_id"
const RequestIDHeader = "X-Request-ID"
RequestIDHeader is the HTTP header name used to propagate the request ID to downstream services.
const RequestIDLocalKey = "request_id"
RequestIDLocalKey is the per-request local-storage key for the request ID used for cross-service correlation. Set it during request initialization via w.Parser.SetLocal(RequestIDLocalKey, requestID).
Variables ¶
var ErrServerTimeout = errors.New("server-side timeout exceeded")
ErrServerTimeout is the sentinel error wrapped inside BuildTimeoutError. Use errors.Is(err, handlers.ErrServerTimeout) to check for server-side timeout errors regardless of additional context.
Functions ¶
func BaseHandler ¶
func BaseHandler[Req any, Resp any, Handler HandlerInterface[Req, Resp]]( core requestCore.RequestCoreInterface, handler Handler, simulation bool, args ...any, ) any
func BuildBaseRemoteHeaders ¶ added in v0.27.0
func BuildBaseRemoteHeaders(w webFramework.WebFramework, appName, correlationID string) map[string]string
BuildBaseRemoteHeaders returns a fresh map of base headers for an outbound remote API call. It sets:
- Accept: application/json
- X-App-ID: <appName>-<pid>
- X-Request-ID: <requestID> (when present in the parser's local storage)
- X-Correlation-ID: <correlationID> (from the argument when non-empty, otherwise from CorrelationIDLocalKey in parser locals when present)
The correlationID argument takes precedence over the parser local. It does not add authorization; RemoteApi.EnsureAuthorization remains responsible for that. Each invocation returns a new map; callers can safely mutate the result.
func BuildRequestURL ¶ added in v0.27.0
BuildRequestURL constructs the full request URL from domain, path, and query. It mirrors the URL construction in libCallApi.PrepareCall, which builds the request URL as Domain + "/" + Path + Query (direct concatenation). Callers must ensure Query is either empty or begins with "?".
func BuildTimeoutError ¶ added in v0.27.0
BuildTimeoutError creates a standardized libError for server-side timeout conditions. The domain is included for context. The returned error wraps ErrServerTimeout so callers can use errors.Is to detect timeout errors.
statusCode selects the status stored in the returned libError. When zero, it defaults to http.StatusRequestTimeout (408). Note: this status is the application-level error status of the returned error only; it does not override the observed remote HTTP status recorded in metrics or TransactionInfo.StatusCode.
func CallApi ¶ added in v0.9.7
func CallApi[Resp any]( w webFramework.WebFramework, core requestCore.RequestCoreInterface, method string, param libCallApi.CallParam) (*Resp, error)
func CallApiForm ¶ added in v0.11.14
func CallApiForm[Req any, Resp any]( w webFramework.WebFramework, core requestCore.RequestCoreInterface, method string, param *libCallApi.RemoteCallParamData[Req, Resp], ) (Resp, error)
func CallApiInternal ¶ added in v0.10.3
func CallApiInternal[Resp any]( w webFramework.WebFramework, core requestCore.RequestCoreInterface, method string, param libCallApi.CallParam) (*Resp, error)
func CallApiJSON ¶ added in v0.9.52
func CallApiJSON[Req any, Resp any]( w webFramework.WebFramework, core requestCore.RequestCoreInterface, method string, param *libCallApi.RemoteCallParamData[Req, Resp], ) (Resp, error)
func CallApiJSONWithOpts ¶ added in v0.27.0
func CallApiJSONWithOpts[Req any, Resp any]( w webFramework.WebFramework, core requestCore.RequestCoreInterface, param *libCallApi.RemoteCallParamData[Req, Resp], opts CallApiOptions, ) (Resp, error)
CallApiJSONWithOpts is an enhanced version of CallApiJSON that adds:
- Prometheus metrics recording via libTracing.RecordHTTPClientCallWithOutcome
- A server-side elapsed-time timeout guard (in addition to the HTTP client timeout)
- HTTP status code preservation via RemoteCallError (independently of the caller's builder)
- Framework-level transaction logging via webFramework.TransactionLogger
- An optional OnComplete callback for application-layer extension hooks
- Optional error normalization via NormalizeError
- Optional retry via RetryPolicy
- Configurable log keys via LogKeys
webFramework.AddLog is called on every code path (request, error, response) and is never skipped or conditionally bypassed. Transaction logging runs after AddLog and never replaces it.
Custom headers: set param.Headers directly (e.g. param.Headers["SIGNATURE"] = "...").
func CallApiNoLog ¶ added in v0.9.24
func CallApiNoLog[Resp any]( w webFramework.WebFramework, 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, error)
func CallRemote ¶ added in v0.9.7
func CallRemote[Req any, Resp any]( core requestCore.RequestCoreInterface, callArg CallArgs[Req, Resp], simulation bool, args ...string, ) any
func CallRemoteWithRespParser ¶ added in v0.9.7
func CallRemoteWithRespParser[Req any, Resp any]( core requestCore.RequestCoreInterface, callArgs CallArgs[Req, Resp], 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 Default ¶ added in v0.10.29
func Default() gin.HandlerFunc
Create a new pagination middleware with default values
func DmlHandler ¶
func DmlHandler[Req libQuery.DmlModel]( core requestCore.RequestCoreInterface, handler DmlHandlerType[Req, map[string]any], simulation bool, ) any
func ExecDML ¶
func ExecDML(request libQuery.DmlModel, key, title string, w webFramework.WebFramework, core requestCore.RequestCoreInterface) (map[string]any, error)
func ExecuteDML ¶
func ExecuteDML(request libQuery.DmlModel, key, title string, w webFramework.WebFramework, core requestCore.RequestCoreInterface) (map[string]any, error)
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 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 GetPersistedRecordID ¶ added in v0.26.0
func GetPersistedRecordID(w webFramework.WebFramework) (any, bool)
func InitPostRequest ¶ added in v0.9.7
func InitPostRequest( w webFramework.WebFramework, reqLog libRequest.RequestPtr, method, url string, checkDuplicate func(libRequest.Request) error, insertRequest func(libRequest.Request) error, 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 NormalizeCallError ¶ added in v0.27.0
NormalizeCallError converts a raw remote-call error into a standardized libError with a consistent API_CALL_ERROR description. It uses libError.Unwrap to detect typed errors and preserves specific error codes that require special handling (e.g., API_CONNECT_TIMED_OUT for retry predicates).
Behavior:
- nil → nil
- API_CONNECT_TIMED_OUT: returned unchanged (retry predicates depend on it)
- API_UNABLE_PARSE_RESP: re-wrapped with useful child text if available
- Other libError values: re-wrapped as API_CALL_ERROR with original context
- Non-libError errors: returned unchanged
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 PreControlDML ¶
func PreControlDML(request libQuery.DmlModel, key, title string, w webFramework.WebFramework, core requestCore.RequestCoreInterface) error
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 QueryHandlerWithOrm ¶ added in v0.16.4
func QueryHandlerWithOrm[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
func QueryWithOrm ¶ added in v0.16.4
func QueryWithOrm[Row, Resp any]( core requestCore.RequestCoreInterface, handler OrmHandlerType[Row, Resp], simulation bool, ) any
func Recovery ¶ added in v0.15.0
func Recovery[Req any, Resp any, Handler HandlerInterface[Req, Resp]]( start time.Time, w webFramework.WebFramework, handler Handler, params HandlerParameters[Req, Resp], trx *HandlerRequest[Req, Resp], core requestCore.RequestCoreInterface, requestInserted bool, panicVal any, )
func SetPersistedRecordID ¶ added in v0.26.0
func SetPersistedRecordID(w webFramework.WebFramework, id any)
func ShouldSkipApiCall ¶ added in v0.27.0
ShouldSkipApiCall reports whether an endpoint matches one of the supplied skip patterns. It is an application-layer decision helper only: it must not be invoked by CallApiJSONWithOpts to control webFramework.AddLog, and a match must never be used to suppress the mandatory request, success, or failure framework logs.
Pattern grammar:
- "endpoint" matches any HTTP method
- "endpoint:METHOD" matches only when the call's method equals METHOD
Matching rules:
- Patterns are trimmed of surrounding whitespace; empty patterns are ignored.
- A pattern containing more than one ':' separator is malformed and is ignored (it never matches), rather than being treated as a broad match.
- Method comparison is case-insensitive.
- Endpoint matching is either an exact match or a path-boundary prefix match: the endpoint equals the pattern endpoint, or the endpoint begins with patternEndpoint + "/". Substring matching is never used, so "api/card" does not match "api/cardholder".
- Leading and trailing slashes are normalized away from both the endpoint and the pattern endpoint before comparison, so "/api/card/", "api/card", and "/api/card" are equivalent.
Types ¶
type ApiCallInfo ¶ added in v0.27.0
type ApiCallInfo = webFramework.TransactionInfo
ApiCallInfo is a compatibility alias for webFramework.TransactionInfo. New code should use webFramework.TransactionInfo directly.
type CachingArgs ¶ added in v0.11.4
type CallApiLogKeys ¶ added in v0.27.0
type CallApiLogKeys struct {
Request string // default: <Method>
Response string // default: <Method>-resp
Failure string // default: <Method>-error
}
CallApiLogKeys holds configurable log key templates for AddLog entries. When a field is empty, the corresponding default is used.
type CallApiOptions ¶ added in v0.27.0
type CallApiOptions struct {
Method string // log key, e.g. "soha-authorize"
Timeout time.Duration // server-side elapsed-time guard (0 = no guard)
// LogKeys, when set, overrides the default AddLog key templates.
// Empty fields fall back to the defaults.
LogKeys CallApiLogKeys
// MetricsRecorder, if set, records Prometheus-style metrics for the call.
// If nil, the default global Prometheus recorder is used.
MetricsRecorder libTracing.HTTPClientMetricsRecorder
// OnComplete is an optional callback invoked after the remote call
// finishes (success or failure). It receives the call metadata so the
// application layer can record it in its own transaction logger, metrics,
// or any other observability system. nil = no callback.
OnComplete func(webFramework.TransactionInfo)
// NormalizeError, when set, is applied to the returned error after
// raw observability (AddLog, metrics, transaction logging, OnComplete)
// has been recorded. This preserves raw Splunk logs while allowing
// callers to normalize the error returned to their consumers.
NormalizeError func(error) error
// RetryPolicy, when set, enables retry behavior. The single-attempt
// logic is reused for each attempt with full observability per attempt.
// nil = no retries (single attempt, existing behavior).
RetryPolicy *libRetry.RetryPolicy
// TimeoutStatusCode selects the status stored in the returned timeout
// libError when the server-side elapsed-time guard fires. Zero = default
// (http.StatusRequestTimeout, 408). This affects ONLY the returned
// libError's application status; TransactionInfo.StatusCode and metrics
// status_class continue to represent the actual observed remote HTTP
// status.
TimeoutStatusCode int
// MaskFunc, when set, is applied to Request, parsed Response, and
// ResponseBody (the result is stored in MaskedResponseBody) before
// TransactionLogger and OnComplete receive TransactionInfo. nil = no
// masking (raw values passed through). Must NOT mutate the outbound
// request or the typed response returned by CallApiJSONWithOpts. Never
// applied to webFramework.AddLog attrs (AddLog uses
// RemoteCallParamData.LogValue which independently masks Authorization).
MaskFunc func(any) any
}
CallApiOptions holds optional parameters for CallApiJSONWithOpts.
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, error)
func (CallArgs[Req, Resp]) Initializer ¶ added in v0.9.7
func (c CallArgs[Req, Resp]) Initializer(req HandlerRequest[Req, Resp]) error
func (CallArgs[Req, Resp]) Parameters ¶ added in v0.9.7
func (c CallArgs[Req, Resp]) Parameters() HandlerParameters[Req, Resp]
func (CallArgs[Req, Resp]) Simulation ¶ added in v0.9.19
func (c CallArgs[Req, Resp]) Simulation(req HandlerRequest[Req, Resp]) (Resp, error)
type CommandReplacer ¶ added in v0.10.29
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, Resp any] struct { Title string Params libCallApi.RemoteCallParamData[Req, Resp] Path string Mode libRequest.Type VerifyHeader 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, error)
func (*ConsumeHandlerType[Req, Resp]) Initializer ¶ added in v0.9.52
func (h *ConsumeHandlerType[Req, Resp]) Initializer(req HandlerRequest[Req, Resp]) error
func (*ConsumeHandlerType[Req, Resp]) Parameters ¶ added in v0.9.52
func (h *ConsumeHandlerType[Req, Resp]) Parameters() HandlerParameters[Req, Resp]
func (*ConsumeHandlerType[Req, Resp]) Simulation ¶ added in v0.9.52
func (h *ConsumeHandlerType[Req, Resp]) Simulation(req HandlerRequest[Req, Resp]) (Resp, error)
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, error)
func (DmlHandlerType[Req, Resp]) Initializer ¶
func (h DmlHandlerType[Req, Resp]) Initializer(req HandlerRequest[Req, Resp]) error
func (DmlHandlerType[Req, Resp]) Parameters ¶
func (h DmlHandlerType[Req, Resp]) Parameters() HandlerParameters[Req, Resp]
func (DmlHandlerType[Req, Resp]) Simulation ¶ added in v0.9.19
func (h DmlHandlerType[Req, Resp]) Simulation(req HandlerRequest[Req, Resp]) (Resp, error)
type FuncPersister ¶ added in v0.26.0
type FuncPersister[Req, Resp any] struct { InsertFn func(path string, req *HandlerRequest[Req, Resp]) error UpdateFn func(path string, req *HandlerRequest[Req, Resp]) error }
func (FuncPersister[Req, Resp]) Insert ¶ added in v0.26.0
func (p FuncPersister[Req, Resp]) Insert(path string, req *HandlerRequest[Req, Resp]) error
func (FuncPersister[Req, Resp]) Update ¶ added in v0.26.0
func (p FuncPersister[Req, Resp]) Update(path string, req *HandlerRequest[Req, Resp]) error
type HandlerInterface ¶
type HandlerInterface[Req any, Resp any] interface { // returns handler title // Request Bodymode // and validate header option // and optional request persistence // and url path of handler Parameters() HandlerParameters[Req, Resp] // runs after validating request Initializer(req HandlerRequest[Req, Resp]) error // main handler runs after initialize Handler(req HandlerRequest[Req, Resp]) (Resp, error) // runs after sending back response Finalizer(req HandlerRequest[Req, Resp]) // handles simulation mode Simulation(req HandlerRequest[Req, Resp]) (Resp, error) }
type HandlerOutcome ¶ added in v0.26.0
type HandlerParameters ¶ added in v0.9.45
type HandlerParameters[Req, Resp any] struct { Title string Body libRequest.Type ValidateHeader bool Path string HasReceipt bool RecoveryHandler func(any) FileResponse bool LogArrays []string LogTags []string Persistence RequestPersister[Req, Resp] // Tracing parameters EnableTracing bool TracingSpanName string }
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 Builder func(status int, rawResp []byte, headers map[string]string) (*Resp, error) Outcome HandlerOutcome Duration time.Duration // Tracing fields Span trace.Span SpanCtx context.Context }
func (*HandlerRequest[Req, Resp]) AddSpanAttribute ¶ added in v0.18.0
func (hr *HandlerRequest[Req, Resp]) AddSpanAttribute(key, value string)
Tracing methods for HandlerRequest
func (*HandlerRequest[Req, Resp]) AddSpanAttributes ¶ added in v0.18.0
func (hr *HandlerRequest[Req, Resp]) AddSpanAttributes(attrs map[string]string)
func (*HandlerRequest[Req, Resp]) AddSpanEvent ¶ added in v0.18.0
func (hr *HandlerRequest[Req, Resp]) AddSpanEvent(name string, attrs map[string]string)
func (HandlerRequest[Req, Resp]) GetParser ¶ added in v0.22.0
func (hr HandlerRequest[Req, Resp]) GetParser() webFramework.RequestParser
GetParser returns the RequestParser from WebFramework for tracing
func (*HandlerRequest[Req, Resp]) RecordSpanError ¶ added in v0.18.0
func (hr *HandlerRequest[Req, Resp]) RecordSpanError(err error, attrs map[string]string)
func (*HandlerRequest[Req, Resp]) SetOutcome ¶ added in v0.26.0
func (trx *HandlerRequest[Req, Resp]) SetOutcome(err error, httpStatus int)
func (*HandlerRequest[Req, Resp]) StartChildSpan ¶ added in v0.18.0
type OrmHandlerType ¶ added in v0.16.4
type OrmHandlerType[Row, Resp any] struct { Title string Path string Mode libRequest.Type VerifyHeader bool Key string DbMode libQuery.DBMode 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][]Row OnEmpty200 bool }
func (OrmHandlerType[Row, Resp]) CacheKey ¶ added in v0.16.4
func (q OrmHandlerType[Row, Resp]) CacheKey(args []any) string
func (OrmHandlerType[Row, Resp]) CacheResult ¶ added in v0.16.4
func (q OrmHandlerType[Row, Resp]) CacheResult(args []any, rows []Row)
func (OrmHandlerType[Row, Resp]) CheckCache ¶ added in v0.16.4
func (q OrmHandlerType[Row, Resp]) CheckCache(args []any) []Row
func (OrmHandlerType[Req, Resp]) Finalizer ¶ added in v0.16.4
func (q OrmHandlerType[Req, Resp]) Finalizer(req HandlerRequest[Req, Resp])
func (OrmHandlerType[Row, Resp]) Handler ¶ added in v0.16.4
func (q OrmHandlerType[Row, Resp]) Handler(req HandlerRequest[Row, Resp]) (Resp, error)
func (OrmHandlerType[Row, Resp]) Initializer ¶ added in v0.16.4
func (q OrmHandlerType[Row, Resp]) Initializer(req HandlerRequest[Row, Resp]) error
func (OrmHandlerType[Row, Resp]) Parameters ¶ added in v0.16.4
func (q OrmHandlerType[Row, Resp]) Parameters() HandlerParameters[Row, Resp]
func (OrmHandlerType[Req, Resp]) Simulation ¶ added in v0.16.4
func (q OrmHandlerType[Req, Resp]) Simulation(req HandlerRequest[Req, Resp]) (Resp, error)
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], error)
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], error)
type QueryHandlerType ¶ added in v0.9.20
type QueryHandlerType[Row, Resp any] struct { Title string Path string Mode libRequest.Type VerifyHeader bool Key string DbMode libQuery.DBMode 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][]Row 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, rows []Row)
func (QueryHandlerType[Row, Resp]) CheckCache ¶ added in v0.11.3
func (q QueryHandlerType[Row, Resp]) CheckCache(args []any) []Row
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, error)
func (QueryHandlerType[Row, Resp]) Initializer ¶ added in v0.9.20
func (q QueryHandlerType[Row, Resp]) Initializer(req HandlerRequest[Row, Resp]) error
func (QueryHandlerType[Row, Resp]) Parameters ¶ added in v0.9.20
func (q QueryHandlerType[Row, Resp]) Parameters() HandlerParameters[Row, Resp]
func (QueryHandlerType[Req, Resp]) Simulation ¶ added in v0.9.20
func (q QueryHandlerType[Req, Resp]) Simulation(req HandlerRequest[Req, Resp]) (Resp, error)
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], error)
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], error)
type RequestPersister ¶ added in v0.25.0
type RequestPersister[Req, Resp any] interface { Insert(path string, req *HandlerRequest[Req, Resp]) error Update(path string, req *HandlerRequest[Req, Resp]) error }
RequestPersister optionally persists request lifecycle data for a handler. When HandlerParameters.Persistence is nil, insert/update are not called.
Insert must succeed before the handler runs; failure aborts the request. Update is best-effort after the response may have been sent; the framework logs errors only and does not retry.
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], error) TranslateWithPaginate([]Row, HandlerRequest[Row, Resp], libRequest.PaginationData) (QueryResp[Resp], error) }
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)