Documentation
¶
Index ¶
- func ServeRequest(req InternalRequest)
- func ToResponse[T InternalModel[R], R any](model T, err error) (*R, error)
- func ToResponseSlice[T InternalModel[R], R any](models []T, err error) ([]*R, error)
- func WriteAPIResponse(w http.ResponseWriter, statusCode int, res any)
- type InternalModel
- type InternalRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ServeRequest ¶
func ServeRequest(req InternalRequest)
ServeRequest processes an HTTP request using the provided InternalRequest configuration.
func ToResponse ¶
func ToResponse[T InternalModel[R], R any](model T, err error) (*R, error)
ToResponse converts an internal model to its response type.
func ToResponseSlice ¶
func ToResponseSlice[T InternalModel[R], R any](models []T, err error) ([]*R, error)
ToResponseSlice converts a slice of internal models to a slice of response types.
func WriteAPIResponse ¶
func WriteAPIResponse(w http.ResponseWriter, statusCode int, res any)
WriteAPIResponse writes the response in JSON format.
Types ¶
type InternalModel ¶
type InternalModel[T any] interface { ToResponse() *T }
InternalModel defines a generic interface for models that support conversion to response types.
type InternalRequest ¶
type InternalRequest struct { W http.ResponseWriter R *http.Request EndpointLogic func() (any, error) // Logic to execute for the endpoint. SuccessCode int // HTTP status code for successful responses. ReqBodyObj any // Optional request body object. }
InternalRequest encapsulates the data required to process a request.
Click to show internal directories.
Click to hide internal directories.