Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppError ¶ added in v1.2.1
AppError represents an application-level error with an error code and optional data. It implements the error interface, making it fully compatible with Go's standard error handling patterns including errors.As() and error wrapping.
Usage:
return nil, model.NewAppError(error_code.InvalidRequest) return nil, model.NewAppErrorWithData(error_code.InvalidRequest, validationErrors)
func CreateError
deprecated
func NewAppError ¶ added in v1.2.1
NewAppError creates an application error with the given error code.
func NewAppErrorWithData ¶ added in v1.2.1
NewAppErrorWithData creates an application error with a code and data payload. The data is typically used to provide additional context (e.g., validation errors).
type BaseResponse ¶ added in v1.2.1
BaseResponse is the API response envelope without a data field. Use this for responses that don't carry a payload (e.g., delete operations, error responses).
OpenAPI annotation example:
@Success 200 {object} model.BaseResponse
@Failure 400 {object} model.BaseResponse
func NewErrorResponse ¶ added in v1.2.1
func NewErrorResponse(code string, message string) *BaseResponse
NewErrorResponse creates an error response without data.
func NewSuccessResponse ¶ added in v1.2.1
func NewSuccessResponse() *BaseResponse
NewSuccessResponse creates a success response without data.
type Response ¶
type Response[T any] struct { BaseResponse Data T `json:"data"` }
Response is the typed API response envelope that embeds BaseResponse. The generic type parameter allows OpenAPI generators to produce accurate schemas instead of opaque "object" types.
OpenAPI annotation example:
@Success 200 {object} model.Response[dto.User]
@Failure 422 {object} model.Response[[]dto.ValidationError]
func NewErrorResponseWithData ¶ added in v1.2.1
NewErrorResponseWithData creates a typed error response with a data payload.
func NewSuccessResponseWithData ¶ added in v1.2.1
NewSuccessResponseWithData creates a typed success response with a data payload.