Documentation ¶
Index ¶
- func CreateHandler[Req, Res any](endpoint Endpoint[Req, Res], requestHandler RequestHandler[Req], ...) http.Handler
- func EncodeToJSON(ctx context.Context, w http.ResponseWriter, obj interface{})
- func EncodeWithStatus[T any](status int, value *T, w http.ResponseWriter) error
- func SendAPIErrorResponse(ctx context.Context, w http.ResponseWriter, apiErr common.APIError)
- func SendErrorResponse(ctx context.Context, w http.ResponseWriter, err error)
- func SendErrorWithStatusAndMessage(ctx context.Context, w http.ResponseWriter, status int, ...)
- func SendUnauthorizedResponse(ctx context.Context, w http.ResponseWriter, details string)
- type CtxKeyRequestURL
- type Endpoint
- type RequestHandler
- type ResponseHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateHandler ¶
func CreateHandler[Req, Res any](endpoint Endpoint[Req, Res], requestHandler RequestHandler[Req], responseHandler ResponseHandler[Res], ) http.Handler
func EncodeToJSON ¶
func EncodeToJSON(ctx context.Context, w http.ResponseWriter, obj interface{})
func EncodeWithStatus ¶
func EncodeWithStatus[T any](status int, value *T, w http.ResponseWriter) error
EncodeWithStatus will attempt to encode the provided `value` into the response writer `w` and will write the status header. If the encoding fails, the http status will not be written to the response writer and the function will return an error instead.
func SendAPIErrorResponse ¶
SendAPIErrorResponse will send an api error which contains relevant information about the failed request to the client. The function will also set the http status according to the provided status.
func SendErrorResponse ¶
func SendErrorResponse(ctx context.Context, w http.ResponseWriter, err error)
SendErrorResponse will send HTTPStatusErrorResponse if err is common.APIError.
Otherwise sends internal server error.
func SendErrorWithStatusAndMessage ¶
func SendErrorWithStatusAndMessage(ctx context.Context, w http.ResponseWriter, status int, message common.ErrorMessageCode, details string)
SendErrorWithStatusAndMessage will construct an api error which contains relevant information about the failed request to the client The function will also set the http status according to the provided status.
func SendUnauthorizedResponse ¶
func SendUnauthorizedResponse(ctx context.Context, w http.ResponseWriter, details string)
SendUnauthorizedResponse sends a standardized StatusUnauthorized response to the client.
Types ¶
type CtxKeyRequestURL ¶
type CtxKeyRequestURL struct{}