handlers

package
v0.0.0-...-212aa6e Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TransformAction

func TransformAction[
	TReqGenerated any,
	TReqApplication any,
	TResGenerated any,
	TResApplication any,
	TActionGenerated handlerActionFunc[TReqGenerated, TResGenerated],
	TActionApplication handlerActionFunc[TReqApplication, TResApplication],
](
	appAction TActionApplication,
	transformer handlerTransformer[TReqGenerated, TResGenerated, TReqApplication, TResApplication],
) TActionGenerated

TransformAction can be used to transform generated action handler to satisfy application layer implementation. Use it to reduce boilerplate code in the controller layer and keep controller slim and declarative.

Errors produced during request or response transformation will be handled with action error handler. You can customize error handling using WithActionErrorHandler option when initializing RootHandler with NewRootHandler method.

Please note that the TransformAction is tightly coupled with the generated code and should not be used outside of the controller layer.

func TransformNoParamsAction

func TransformNoParamsAction[
	TResGenerated any,
	TResApplication any,
	TActionGenerated handlerActionFuncNoParams[void, TResGenerated],
	TActionApplication handlerActionFuncNoParams[void, TResApplication],
](
	appAction TActionApplication,
	transformer handlerResponseTransformer[TResGenerated, TResApplication],
) TActionGenerated

TransformNoParamsAction is a variation of TransformAction for actions without parameters. Please see the TransformAction for more details.

func TransformNoResponseAction

func TransformNoResponseAction[
	TReqGenerated any,
	TReqApplication any,
	TActionGenerated handlerActionFuncNoResponse[TReqGenerated, void],
	TActionApplication handlerActionFuncNoResponse[TReqApplication, void],
](
	appAction TActionApplication,
	transformer handlerRequestTransformer[TReqGenerated, TReqApplication],
) TActionGenerated

TransformNoResponseAction is a variation of TransformAction for actions without response body. Please see the TransformAction for more details.

Types

type ArraysController

type ArraysController interface {
	// POST /arrays/nullable-required-validation/{simpleItems1}/{simpleItems2}
	//
	// Request type: ArraysNullableRequiredValidationParams,
	//
	// Response type: none
	ArraysNullableRequiredValidation(NoResponseHandlerBuilder[*ArraysNullableRequiredValidationParams]) http.Handler

	// POST /arrays/range-validation/{simpleItems1}/{simpleItems2}
	//
	// Request type: ArraysRangeValidationParams,
	//
	// Response type: none
	ArraysRangeValidation(NoResponseHandlerBuilder[*ArraysRangeValidationParams]) http.Handler

	// POST /arrays/required-validation/{simpleItems1}/{simpleItems2}
	//
	// Request type: ArraysRequiredValidationParams,
	//
	// Response type: none
	ArraysRequiredValidation(NoResponseHandlerBuilder[*ArraysRequiredValidationParams]) http.Handler
}

type BehaviorController

type BehaviorController interface {
	// GET /behavior/no-params-no-response
	//
	// Request type: none
	//
	// Response type: none
	BehaviorNoParamsNoResponse(NoParamsNoResponseHandlerBuilder) http.Handler

	// GET /behavior/no-params-with-response
	//
	// Request type: none
	//
	// Response type: BehaviorNoParamsWithResponse202Response
	BehaviorNoParamsWithResponse(NoParamsHandlerBuilder[*BehaviorNoParamsWithResponse202Response]) http.Handler

	// GET /behavior/no-status-defined
	//
	// Request type: none
	//
	// Response type: none
	BehaviorNoStatusDefined(NoParamsNoResponseHandlerBuilder) http.Handler

	// POST /behavior/with-params-and-response
	//
	// Request type: BehaviorWithParamsAndResponseParams,
	//
	// Response type: BehaviorWithParamsAndResponseResponseBody
	BehaviorWithParamsAndResponse(HandlerBuilder[
		*BehaviorWithParamsAndResponseParams,
		*BehaviorWithParamsAndResponseResponseBody,
	]) http.Handler

	// GET /behavior/with-params-no-response
	//
	// Request type: BehaviorWithParamsNoResponseParams,
	//
	// Response type: none
	BehaviorWithParamsNoResponse(NoResponseHandlerBuilder[*BehaviorWithParamsNoResponseParams]) http.Handler

	// POST /behavior/with-status-defined
	//
	// Request type: none
	//
	// Response type: none
	BehaviorWithStatusDefined(NoParamsNoResponseHandlerBuilder) http.Handler
}

type BehaviorIDNamesController

type BehaviorIDNamesController interface {
	// POST /behavior/id-names/{id}/{endsWithId}/{theIdInTheMiddle}
	//
	// Request type: BehaviorNamesWithIDParams,
	//
	// Response type: BehaviorNamesWithIDData
	BehaviorNamesWithID(HandlerBuilder[
		*BehaviorNamesWithIDParams,
		*BehaviorNamesWithIDData,
	]) http.Handler
}

type BehaviorNoParamsNoResponseIsolatedController

type BehaviorNoParamsNoResponseIsolatedController interface {
	// GET /behavior/no-params-no-response-isolated
	//
	// Request type: none
	//
	// Response type: none
	BehaviorNoParamsNoResponse(NoParamsNoResponseHandlerBuilder) http.Handler
}

type BooleanController

type BooleanController interface {
	// POST /boolean/array-items/{boolParam1}/{boolParam2}
	//
	// Request type: BooleanArrayItemsParams,
	//
	// Response type: none
	BooleanArrayItems(NoResponseHandlerBuilder[*BooleanArrayItemsParams]) http.Handler

	// POST /boolean/nullable/{boolParam1}/{boolParam2}
	//
	// Request type: BooleanNullableParams,
	//
	// Response type: none
	BooleanNullable(NoResponseHandlerBuilder[*BooleanNullableParams]) http.Handler

	// POST /boolean/nullable-array-items/{boolParam1}/{boolParam2}
	//
	// Request type: BooleanNullableArrayItemsParams,
	//
	// Response type: none
	BooleanNullableArrayItems(NoResponseHandlerBuilder[*BooleanNullableArrayItemsParams]) http.Handler

	// POST /boolean/parsing/{boolParam1}/{boolParam2}
	//
	// Request type: BooleanParsingParams,
	//
	// Response type: none
	BooleanParsing(NoResponseHandlerBuilder[*BooleanParsingParams]) http.Handler

	// POST /boolean/required-validation
	//
	// Request type: BooleanRequiredValidationParams,
	//
	// Response type: none
	BooleanRequiredValidation(NoResponseHandlerBuilder[*BooleanRequiredValidationParams]) http.Handler
}

type HandlerBuilder

type HandlerBuilder[TReq any, TRes any] genericHandlerBuilder[
	TReq,
	TRes,
	handlerActionFunc[TReq, TRes],
	httpHandlerActionFunc[TReq, TRes],
]

type NoParamsHandlerBuilder

type NoParamsHandlerBuilder[TRes any] genericHandlerBuilder[
	void,
	TRes,
	handlerActionFuncNoParams[void, TRes],
	httpHandlerActionFuncNoParams[void, TRes],
]

type NoParamsNoResponseHandlerBuilder

type NoParamsNoResponseHandlerBuilder genericHandlerBuilder[
	void,
	void,
	handlerActionFuncNoParamsNoResponse[void, void],
	httpHandlerActionFuncNoParamsNoResponse[void, void],
]

type NoResponseHandlerBuilder

type NoResponseHandlerBuilder[TReq any] genericHandlerBuilder[
	TReq,
	void,
	handlerActionFuncNoResponse[TReq, void],
	httpHandlerActionFuncNoResponse[TReq, void],
]

type NumericTypesController

type NumericTypesController interface {
	// POST /numeric-types/array-items/{numberAny}/{numberFloat}/{numberDouble}/{numberInt}/{numberInt32}/{numberInt64}
	//
	// Request type: NumericTypesArrayItemsParams,
	//
	// Response type: none
	NumericTypesArrayItems(NoResponseHandlerBuilder[*NumericTypesArrayItemsParams]) http.Handler

	// POST /numeric-types/nullable/{numberAny}/{numberFloat}/{numberDouble}/{numberInt}/{numberInt32}/{numberInt64}
	//
	// Request type: NumericTypesNullableParams,
	//
	// Response type: none
	NumericTypesNullable(NoResponseHandlerBuilder[*NumericTypesNullableParams]) http.Handler

	// POST /numeric-types/nullable-array-items/{numberAny}/{numberFloat}/{numberDouble}/{numberInt}/{numberInt32}/{numberInt64}
	//
	// Request type: NumericTypesNullableArrayItemsParams,
	//
	// Response type: none
	NumericTypesNullableArrayItems(NoResponseHandlerBuilder[*NumericTypesNullableArrayItemsParams]) http.Handler

	// POST /numeric-types/parsing/{numberAny}/{numberFloat}/{numberDouble}/{numberInt}/{numberInt32}/{numberInt64}
	//
	// Request type: NumericTypesParsingParams,
	//
	// Response type: none
	NumericTypesParsing(NoResponseHandlerBuilder[*NumericTypesParsingParams]) http.Handler

	// POST /numeric-types/range-validation/{numberAny}/{numberFloat}/{numberDouble}/{numberInt}/{numberInt32}/{numberInt64}
	//
	// Request type: NumericTypesRangeValidationParams,
	//
	// Response type: none
	NumericTypesRangeValidation(NoResponseHandlerBuilder[*NumericTypesRangeValidationParams]) http.Handler

	// POST /numeric-types/range-validation-exclusive/{numberAny}/{numberFloat}/{numberDouble}/{numberInt}/{numberInt32}/{numberInt64}
	//
	// Request type: NumericTypesRangeValidationExclusiveParams,
	//
	// Response type: none
	NumericTypesRangeValidationExclusive(NoResponseHandlerBuilder[*NumericTypesRangeValidationExclusiveParams]) http.Handler

	// GET /numeric-types/required-validation
	//
	// Request type: NumericTypesRequiredValidationParams,
	//
	// Response type: none
	NumericTypesRequiredValidation(NoResponseHandlerBuilder[*NumericTypesRequiredValidationParams]) http.Handler
}

type ObjectsController

type ObjectsController interface {
	// POST /objects/arrays
	//
	// Request type: ObjectsArrayBodyDirectParams,
	//
	// Response type: none
	ObjectsArrayBodyDirect(NoResponseHandlerBuilder[*ObjectsArrayBodyDirectParams]) http.Handler

	// PUT /objects/arrays
	//
	// Request type: ObjectsArrayBodyNestedParams,
	//
	// Response type: none
	ObjectsArrayBodyNested(NoResponseHandlerBuilder[*ObjectsArrayBodyNestedParams]) http.Handler

	// POST /objects/deeply-nested
	//
	// Request type: ObjectsDeeplyNestedParams,
	//
	// Response type: none
	ObjectsDeeplyNested(NoResponseHandlerBuilder[*ObjectsDeeplyNestedParams]) http.Handler

	// PUT /objects/nullable-body
	//
	// Request type: ObjectsNullableOptionalBodyParams,
	//
	// Response type: none
	ObjectsNullableOptionalBody(NoResponseHandlerBuilder[*ObjectsNullableOptionalBodyParams]) http.Handler

	// POST /objects/nullable-body
	//
	// Request type: ObjectsNullableRequiredBodyParams,
	//
	// Response type: none
	ObjectsNullableRequiredBody(NoResponseHandlerBuilder[*ObjectsNullableRequiredBodyParams]) http.Handler

	// PUT /objects/required-body
	//
	// Request type: ObjectsOptionalBodyParams,
	//
	// Response type: none
	ObjectsOptionalBody(NoResponseHandlerBuilder[*ObjectsOptionalBodyParams]) http.Handler

	// POST /objects/required-body
	//
	// Request type: ObjectsRequiredBodyParams,
	//
	// Response type: none
	ObjectsRequiredBody(NoResponseHandlerBuilder[*ObjectsRequiredBodyParams]) http.Handler

	// POST /objects/required-nested-objects
	//
	// Request type: ObjectsRequiredNestedObjectsParams,
	//
	// Response type: none
	ObjectsRequiredNestedObjects(NoResponseHandlerBuilder[*ObjectsRequiredNestedObjectsParams]) http.Handler
}

type RootHandler

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

RootHandler is a central point of the generated HTTP server. It is responsible for registering routes and customizing router behavior. The RootHandler implements http.Handler interface and can be used as a standard http.Handler in any context that expects it.

func NewRootHandler

func NewRootHandler(router httpRouter, opts ...RootHandlerOpt) *RootHandler

NewRootHandler creates a new instance of the root handler.

func (*RootHandler) RegisterArraysRoutes

func (rootHandler *RootHandler) RegisterArraysRoutes(controller ArraysController) *RootHandler

RegisterArraysRoutes will attach the following routes to the root handler:

- POST /arrays/nullable-required-validation/{simpleItems1}/{simpleItems2}

- POST /arrays/range-validation/{simpleItems1}/{simpleItems2}

- POST /arrays/required-validation/{simpleItems1}/{simpleItems2}

Routes will use provided controller to handle requests.

func (*RootHandler) RegisterBehaviorIDNamesRoutes

func (rootHandler *RootHandler) RegisterBehaviorIDNamesRoutes(controller BehaviorIDNamesController) *RootHandler

RegisterBehaviorIDNamesRoutes will attach the following routes to the root handler:

- POST /behavior/id-names/{id}/{endsWithId}/{theIdInTheMiddle}

Routes will use provided controller to handle requests.

func (*RootHandler) RegisterBehaviorNoParamsNoResponseIsolatedRoutes

func (rootHandler *RootHandler) RegisterBehaviorNoParamsNoResponseIsolatedRoutes(controller BehaviorNoParamsNoResponseIsolatedController) *RootHandler

RegisterBehaviorNoParamsNoResponseIsolatedRoutes will attach the following routes to the root handler:

- GET /behavior/no-params-no-response-isolated

Routes will use provided controller to handle requests.

func (*RootHandler) RegisterBehaviorRoutes

func (rootHandler *RootHandler) RegisterBehaviorRoutes(controller BehaviorController) *RootHandler

RegisterBehaviorRoutes will attach the following routes to the root handler:

- GET /behavior/no-params-no-response

- GET /behavior/no-params-with-response

- GET /behavior/no-status-defined

- POST /behavior/with-params-and-response

- GET /behavior/with-params-no-response

- POST /behavior/with-status-defined

Routes will use provided controller to handle requests.

func (*RootHandler) RegisterBooleanRoutes

func (rootHandler *RootHandler) RegisterBooleanRoutes(controller BooleanController) *RootHandler

RegisterBooleanRoutes will attach the following routes to the root handler:

- POST /boolean/array-items/{boolParam1}/{boolParam2}

- POST /boolean/nullable/{boolParam1}/{boolParam2}

- POST /boolean/nullable-array-items/{boolParam1}/{boolParam2}

- POST /boolean/parsing/{boolParam1}/{boolParam2}

- POST /boolean/required-validation

Routes will use provided controller to handle requests.

func (*RootHandler) RegisterNumericTypesRoutes

func (rootHandler *RootHandler) RegisterNumericTypesRoutes(controller NumericTypesController) *RootHandler

RegisterNumericTypesRoutes will attach the following routes to the root handler:

- POST /numeric-types/array-items/{numberAny}/{numberFloat}/{numberDouble}/{numberInt}/{numberInt32}/{numberInt64}

- POST /numeric-types/nullable/{numberAny}/{numberFloat}/{numberDouble}/{numberInt}/{numberInt32}/{numberInt64}

- POST /numeric-types/nullable-array-items/{numberAny}/{numberFloat}/{numberDouble}/{numberInt}/{numberInt32}/{numberInt64}

- POST /numeric-types/parsing/{numberAny}/{numberFloat}/{numberDouble}/{numberInt}/{numberInt32}/{numberInt64}

- POST /numeric-types/range-validation/{numberAny}/{numberFloat}/{numberDouble}/{numberInt}/{numberInt32}/{numberInt64}

- POST /numeric-types/range-validation-exclusive/{numberAny}/{numberFloat}/{numberDouble}/{numberInt}/{numberInt32}/{numberInt64}

- GET /numeric-types/required-validation

Routes will use provided controller to handle requests.

func (*RootHandler) RegisterObjectsRoutes

func (rootHandler *RootHandler) RegisterObjectsRoutes(controller ObjectsController) *RootHandler

RegisterObjectsRoutes will attach the following routes to the root handler:

- POST /objects/arrays

- PUT /objects/arrays

- POST /objects/deeply-nested

- PUT /objects/nullable-body

- POST /objects/nullable-body

- PUT /objects/required-body

- POST /objects/required-body

- POST /objects/required-nested-objects

Routes will use provided controller to handle requests.

func (*RootHandler) RegisterStringTypesRoutes

func (rootHandler *RootHandler) RegisterStringTypesRoutes(controller StringTypesController) *RootHandler

RegisterStringTypesRoutes will attach the following routes to the root handler:

- POST /string-types/array-items-range-validation/{unformattedStr}/{customFormatStr}/{dateStr}/{dateTimeStr}/{byteStr}

- POST /string-types/arrays-parsing/{unformattedStr}/{customFormatStr}/{dateStr}/{dateTimeStr}/{byteStr}

- POST /string-types/enums/{inlineEnumParam}/{nullableInlineEnumParam}/{refEnumParam}/{nullableRefEnumParam}

- POST /string-types/nullable-array-items/{unformattedStr}/{customFormatStr}/{dateStr}/{dateTimeStr}/{byteStr}

- POST /string-types/nullable-parsing/{unformattedStr}/{customFormatStr}/{dateStr}/{dateTimeStr}/{byteStr}

- POST /string-types/nullable-required-validation

- POST /string-types/parsing/{unformattedStr}/{customFormatStr}/{dateStr}/{dateTimeStr}/{byteStr}

- POST /string-types/pattern-validation/{unformattedStr}/{customFormatStr}/{dateStr}/{dateTimeStr}

- POST /string-types/range-validation/{unformattedStr}/{customFormatStr}/{dateStr}/{dateTimeStr}/{byteStr}

- POST /string-types/required-validation

Routes will use provided controller to handle requests.

func (*RootHandler) ServeHTTP

func (rootHandler *RootHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RootHandlerOpt

type RootHandlerOpt func(*RootHandler)

func WithActionErrorHandler

func WithActionErrorHandler(handler errorHandlerFunc) RootHandlerOpt

WithActionErrorHandler allows to set custom handler for action errors. Action errors are errors that occur during controller action execution. The default implementation will respond with 500 status code and no output. The default implementation will also log the error using configured logger.

func WithLogger

func WithLogger(logger slogLogger) RootHandlerOpt

WithLogger allows to set custom logger for the root handler. The default logger is slog.Default().

func WithParsingErrorHandler

func WithParsingErrorHandler(handler errorHandlerFunc) RootHandlerOpt

WithParsingErrorHandler allows to set custom handler for parsing errors. Parsing errors are errors that occur during request parsing and validation. The default implementation will respond with 400 status code and validation errors serialized as JSON. No sensitive information is exposed, just field names. The default implementation will also log the error using configured logger.

func WithResponseErrorHandler

func WithResponseErrorHandler(handler errorHandlerFunc) RootHandlerOpt

WithResponseErrorHandler allows to set custom handler for response errors. Response errors are errors that occur while writing response. The default implementation will attempt to respond with 500 status code and no output. The default implementation will also log the error using configured logger.

type StringTypesController

type StringTypesController interface {
	// POST /string-types/array-items-range-validation/{unformattedStr}/{customFormatStr}/{dateStr}/{dateTimeStr}/{byteStr}
	//
	// Request type: StringTypesArrayItemsRangeValidationParams,
	//
	// Response type: none
	StringTypesArrayItemsRangeValidation(NoResponseHandlerBuilder[*StringTypesArrayItemsRangeValidationParams]) http.Handler

	// POST /string-types/arrays-parsing/{unformattedStr}/{customFormatStr}/{dateStr}/{dateTimeStr}/{byteStr}
	//
	// Request type: StringTypesArraysParsingParams,
	//
	// Response type: none
	StringTypesArraysParsing(NoResponseHandlerBuilder[*StringTypesArraysParsingParams]) http.Handler

	// POST /string-types/enums/{inlineEnumParam}/{nullableInlineEnumParam}/{refEnumParam}/{nullableRefEnumParam}
	//
	// Request type: StringTypesEnumsParams,
	//
	// Response type: none
	StringTypesEnums(NoResponseHandlerBuilder[*StringTypesEnumsParams]) http.Handler

	// POST /string-types/nullable-array-items/{unformattedStr}/{customFormatStr}/{dateStr}/{dateTimeStr}/{byteStr}
	//
	// Request type: StringTypesNullableArrayItemsParams,
	//
	// Response type: none
	StringTypesNullableArrayItems(NoResponseHandlerBuilder[*StringTypesNullableArrayItemsParams]) http.Handler

	// POST /string-types/nullable-parsing/{unformattedStr}/{customFormatStr}/{dateStr}/{dateTimeStr}/{byteStr}
	//
	// Request type: StringTypesNullableParsingParams,
	//
	// Response type: none
	StringTypesNullableParsing(NoResponseHandlerBuilder[*StringTypesNullableParsingParams]) http.Handler

	// POST /string-types/nullable-required-validation
	//
	// Request type: StringTypesNullableRequiredValidationParams,
	//
	// Response type: none
	StringTypesNullableRequiredValidation(NoResponseHandlerBuilder[*StringTypesNullableRequiredValidationParams]) http.Handler

	// POST /string-types/parsing/{unformattedStr}/{customFormatStr}/{dateStr}/{dateTimeStr}/{byteStr}
	//
	// Request type: StringTypesParsingParams,
	//
	// Response type: none
	StringTypesParsing(NoResponseHandlerBuilder[*StringTypesParsingParams]) http.Handler

	// POST /string-types/pattern-validation/{unformattedStr}/{customFormatStr}/{dateStr}/{dateTimeStr}
	//
	// Request type: StringTypesPatternValidationParams,
	//
	// Response type: none
	StringTypesPatternValidation(NoResponseHandlerBuilder[*StringTypesPatternValidationParams]) http.Handler

	// POST /string-types/range-validation/{unformattedStr}/{customFormatStr}/{dateStr}/{dateTimeStr}/{byteStr}
	//
	// Request type: StringTypesRangeValidationParams,
	//
	// Response type: none
	StringTypesRangeValidation(NoResponseHandlerBuilder[*StringTypesRangeValidationParams]) http.Handler

	// POST /string-types/required-validation
	//
	// Request type: StringTypesRequiredValidationParams,
	//
	// Response type: none
	StringTypesRequiredValidation(NoResponseHandlerBuilder[*StringTypesRequiredValidationParams]) http.Handler
}

Jump to

Keyboard shortcuts

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