model

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 0 Imported by: 0

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

type AppError struct {
	Code string
	Data any
}

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 CreateError(code string, data any) *AppError

Deprecated: CreateError exists for backward compatibility.

func NewAppError added in v1.2.1

func NewAppError(code string) *AppError

NewAppError creates an application error with the given error code.

func NewAppErrorWithData added in v1.2.1

func NewAppErrorWithData(code string, data any) *AppError

NewAppErrorWithData creates an application error with a code and data payload. The data is typically used to provide additional context (e.g., validation errors).

func (*AppError) Error added in v1.2.1

func (e *AppError) Error() string

Error implements the error interface, returning the error code.

type BaseResponse added in v1.2.1

type BaseResponse struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

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 CreateResponse deprecated

func CreateResponse(code string, message string, data any) *Response[any]

Deprecated: CreateResponse exists for backward compatibility.

func NewErrorResponseWithData added in v1.2.1

func NewErrorResponseWithData[T any](code string, message string, data T) *Response[T]

NewErrorResponseWithData creates a typed error response with a data payload.

func NewSuccessResponseWithData added in v1.2.1

func NewSuccessResponseWithData[T any](data T) *Response[T]

NewSuccessResponseWithData creates a typed success response with a data payload.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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