endpoint

package
v0.0.0-...-214c4de Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

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.

Jump to

Keyboard shortcuts

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