Documentation
¶
Overview ¶
Package model contains the request/response models for REST APIs
Package model contains the request/response models for REST APIs
Index ¶
- type ApiResponse
- func ErrorResponse(errorMessage, message string) ApiResponse[any]
- func SimpleErrorResponse(errorMessage string) ApiResponse[any]
- func SimpleSuccessResponse(message string) ApiResponse[any]
- func SuccessListResponse[T any](items []T) ApiResponse[[]T]
- func SuccessListResponseWithMessage[T any](items []T, message string) ApiResponse[[]T]
- func SuccessPagedResponse[T any](items []T, totalCount int64, page, size int) ApiResponse[Page[T]]
- func SuccessResponse[T any](data T) ApiResponse[T]
- func SuccessResponseWithMessage[T any](data T, message string) ApiResponse[T]
- type AsyncJobResponse
- type EncryptionTestRequest
- type Page
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApiResponse ¶ added in v0.4.6
type ApiResponse[T any] struct { Success bool `json:"success" example:"true"` // Indicates whether the API call was successful Data T `json:"data,omitempty"` // Contains the actual response data (single object, list, or page) Message string `json:"message,omitempty" example:"Operation successful"` // Optional message for additional context Error string `json:"error,omitempty" example:"Error message if failure"` // Error message for failed responses }
ApiResponse represents a standardized API response structure. It uses generics to support different data types for successful responses.
For successful responses:
- Data field contains the result object, array, or paginated result
For error responses:
- Error field contains the error message
func ErrorResponse ¶ added in v0.4.6
func ErrorResponse(errorMessage, message string) ApiResponse[any]
ErrorResponse creates an error API response with a structured error. T is set to 'any' as there is no data to return.
func SimpleErrorResponse ¶ added in v0.4.6
func SimpleErrorResponse(errorMessage string) ApiResponse[any]
SimpleErrorResponse creates an error API response from a simple error message. T is set to 'any' as there is no data to return.
func SimpleSuccessResponse ¶ added in v0.5.1
func SimpleSuccessResponse(message string) ApiResponse[any]
SimpleSuccessResponse creates a successful API response with a simple message. T is set to 'any' as there is no data to return.
func SuccessListResponse ¶ added in v0.4.6
func SuccessListResponse[T any](items []T) ApiResponse[[]T]
SuccessListResponse is a convenience wrapper for list responses. It explicitly takes a slice and returns ApiResponse[[]T]. This ensures that the Data field is always a JSON array. T is the type of items in the list.
func SuccessListResponseWithMessage ¶ added in v0.4.6
func SuccessListResponseWithMessage[T any](items []T, message string) ApiResponse[[]T]
SuccessListResponseWithMessage creates a successful list API response with a custom message. T is the type of items in the list.
func SuccessPagedResponse ¶ added in v0.5.1
func SuccessPagedResponse[T any](items []T, totalCount int64, page, size int) ApiResponse[Page[T]]
SuccessPagedResponse creates a successful API response with pagination details. It automatically wraps the items and metadata into a Page struct. T is the type of items in the page.
func SuccessResponse ¶ added in v0.4.6
func SuccessResponse[T any](data T) ApiResponse[T]
SuccessResponse creates a successful API response for a single object or any generic data. T is the type of the response data. Usage:
- Single Object: SuccessResponse(user) -> Data: User
- Raw List: SuccessResponse(users) -> Data: []User
func SuccessResponseWithMessage ¶ added in v0.4.6
func SuccessResponseWithMessage[T any](data T, message string) ApiResponse[T]
SuccessResponseWithMessage creates a successful API response with a custom message. T is the type of the response data.
type AsyncJobResponse ¶ added in v0.5.1
type AsyncJobResponse struct {
// ReqID is the unique identifier for tracking the request status.
// This is the same as the X-Request-Id header value.
ReqID string `json:"reqId" example:"1706500000000000000"`
// Status is the current status of the request (Handling, Success, Error).
Status string `json:"status" example:"Handling"`
// StatusURL is the relative URL to check the request status.
StatusURL string `json:"statusUrl" example:"/beetle/request/1706500000000000000"`
}
AsyncJobResponse represents the response for asynchronous job submission. Returned with HTTP 202 Accepted status for long-running operations.
type EncryptionTestRequest ¶ added in v0.5.1
type EncryptionTestRequest struct {
// PublicKeyBundle contains the public key obtained from GET /migration/data/encryptionKey
PublicKeyBundle transx.PublicKeyBundle `json:"publicKeyBundle"`
// Model is the plaintext DataMigrationModel to be encrypted
Model transx.DataMigrationModel `json:"model"`
}
EncryptionTestRequest represents the request body for encryption test API. It contains the public key bundle and the plaintext model to be encrypted.
type Page ¶ added in v0.5.1
type Page[T any] struct { Items []T `json:"items"` // List of items in the current page TotalCount int64 `json:"total_count" example:"1"` // Total number of items across all pages Page int `json:"page" example:"1"` // Current page number (1-based index) Size int `json:"size" example:"10"` // Number of items per page HasNext bool `json:"has_next" example:"true"` // Indicates if there is a next page }
Page represents a standardized structure for paginated results. This struct is intended to be used within the ApiResponse.Data field.