tkPresentation

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: MIT Imports: 22 Imported by: 2

Documentation

Index

Constants

View Source
const (
	EnvsInspectorEnvFilePathEnvVarName string = "ENV_FILE_PATH"
)

Variables

This section is empty.

Functions

func LiaisonApiResponseEmitter added in v0.1.1

func LiaisonApiResponseEmitter(
	echoContext echo.Context,
	liaisonResponse LiaisonResponse,
) error

func LiaisonCliResponseRenderer added in v0.1.1

func LiaisonCliResponseRenderer(liaisonResponse LiaisonResponse)

func PaginationParser added in v0.1.1

func PaginationParser(
	defaultPagination tkDto.Pagination,
	untrustedInput map[string]any,
) (parsedPagination tkDto.Pagination, err error)

func RequiredParamsInspector added in v0.0.4

func RequiredParamsInspector(paramsReceived map[string]any, paramsRequired []string) error

func StringSliceValueObjectParser

func StringSliceValueObjectParser[TypedObject any](
	rawInputValues any,
	valueObjectConstructor func(any) (TypedObject, error),
) []TypedObject

StringSliceValueObjectParser converts various input formats into a slice of typed objects. It accepts: - nil (returns empty slice) - string (splits by ";" or "," and parses each element) - slice (parses each element) - single value (parses as one element)

The valueObjectConstructor function is used to convert each raw value into the desired type. Invalid values are logged and skipped.

func TimeParamsParser added in v0.1.1

func TimeParamsParser(
	timeParamNames []string,
	untrustedInput map[string]any,
) map[string]*tkValueObject.UnixTime

This function parses time parameters from untrusted input. Time parameters are almost always optional, so it returns a map of pointers to tkValueObject.UnixTime. This allows the caller to easily determine if a time parameter was provided by checking if the pointer is nil. The parsed time parameters can then be directly set in a DTO.

Types

type ApiResponseWrapper added in v0.1.1

type ApiResponseWrapper struct {
	Status          int    `json:"status"`
	Body            any    `json:"body"`
	ReadableMessage string `json:"readableMessage"`
}

func NewApiResponseWrapper added in v0.1.1

func NewApiResponseWrapper(
	status int,
	readableMessage string,
	body any,
) ApiResponseWrapper

type EnvsInspector added in v0.1.0

type EnvsInspector struct {
	// contains filtered or unexported fields
}

func NewEnvsInspector added in v0.1.0

func NewEnvsInspector(
	envFilePath *tkValueObject.UnixAbsoluteFilePath,
	requiredEnvVars, autoFillableEnvVars []string,
) *EnvsInspector

func (*EnvsInspector) Inspect added in v0.1.0

func (envsInspector *EnvsInspector) Inspect() (err error)

type LiaisonResponse added in v0.1.1

type LiaisonResponse struct {
	Status          LiaisonResponseStatus `json:"status"`
	ReadableMessage string                `json:"readableMessage"`
	Body            any                   `json:"body"`
}

func NewLiaisonResponse added in v0.1.1

func NewLiaisonResponse(
	status LiaisonResponseStatus,
	readableMessage string,
	body any,
) LiaisonResponse

type LiaisonResponseStatus added in v0.1.1

type LiaisonResponseStatus string
const (
	LiaisonResponseStatusSuccess      LiaisonResponseStatus = "success"
	LiaisonResponseStatusCreated      LiaisonResponseStatus = "created"
	LiaisonResponseStatusMultiStatus  LiaisonResponseStatus = "multiStatus"
	LiaisonResponseStatusUserError    LiaisonResponseStatus = "userError"
	LiaisonResponseStatusUnauthorized LiaisonResponseStatus = "unauthorized"
	LiaisonResponseStatusForbidden    LiaisonResponseStatus = "forbidden"
	LiaisonResponseStatusInfraError   LiaisonResponseStatus = "infraError"
	LiaisonResponseStatusUnknownError LiaisonResponseStatus = "unknownError"
)

type RequestInputReader added in v0.1.1

type RequestInputReader struct {
}

func (RequestInputReader) FormUrlEncodedDataProcessor added in v0.1.1

func (reader RequestInputReader) FormUrlEncodedDataProcessor(
	requestBody map[string]any, formData map[string][]string,
) map[string]any

func (RequestInputReader) MultipartFilesProcessor added in v0.1.1

func (RequestInputReader) MultipartFilesProcessor(
	filesByKey map[string][]*multipart.FileHeader,
) map[string]*multipart.FileHeader

func (RequestInputReader) Reader added in v0.1.1

func (reader RequestInputReader) Reader(echoContext echo.Context) (map[string]any, error)

RequestInputReader.Reader extracts and normalizes input data from an HTTP request into a flat map[string]any.

It processes the request body based on Content-Type, merges query parameters, path parameters, and optionally includes operator context information.

Content-Type handling:

  • application/json: Parses JSON body directly into the map. Returns "InvalidJsonBody" error if JSON is malformed.
  • application/x-www-form-urlencoded: Processes form data, preserving multiple values as string slices when a key appears more than once. Supports dot notation for nested structures (e.g., "user.name" becomes map["user"]["name"]).
  • multipart/form-data: Processes form fields similar to URL-encoded data. File uploads are normalized under the "files" key, with multiple files indexed as "key_0", "key_1", etc. Returns "InvalidMultipartFormData" error if the multipart form cannot be parsed.
  • Other/missing Content-Type: Returns "InvalidContentType" error.

Query parameters:

Query parameters are merged into the result map. When a query parameter has multiple
values (e.g., ?tags=tag1&tags=tag2), only the FIRST value is captured. This is a design
decision to optimize for the common single-value case (~99% of use cases).

For the rare cases where multiple values are needed, use a delimiter at the controller
level. For example: ?tags=tag1;tag2 and split on ";" in your controller logic.

Route Path parameters:

All Echo route path parameters (e.g., :id, :name) are merged into the result map.

Operator context (if present in Echo context):

  • operatorAccountId: Extracted from context key and included in the result map.
  • operatorIpAddress: Always populated using the real client IP address via RealIP().

Returns:

  • A map[string]any containing all extracted request data, or
  • An echo.HTTPError with status 400 (Bad Request) and a descriptive message if parsing fails.

func (RequestInputReader) StringDotNotationToHierarchicalMap added in v0.1.1

func (reader RequestInputReader) StringDotNotationToHierarchicalMap(
	hierarchicalMap map[string]any, remainingKeys []string, finalValue string,
) map[string]any

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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