Documentation
¶
Index ¶
- func ErrorGRPC[T any](ctx context.Context, err error, options ...Option) (T, error)
- func ErrorHTTP(w http.ResponseWriter, r *http.Request, err error, options ...Option)
- func HTML(w http.ResponseWriter, r *http.Request, v []byte, options ...Option)
- func JSON(w http.ResponseWriter, r *http.Request, v any, options ...Option)
- func SetGRPCErrorResponder(responder GRPCErrorResponder)
- func SetHTMLTemplateProvider(templater HTMLTemplateProvider)
- func SetHTTPErrorResponder(responder HTTPErrorResponder)
- func Status(w http.ResponseWriter, _ *http.Request, statusCode int, options ...Option)
- func TEXT(w http.ResponseWriter, r *http.Request, v []byte, options ...Option)
- func TemplateHTML(w http.ResponseWriter, r *http.Request, name string, v any, options ...Option)
- type GRPCErrorResponder
- type HTMLTemplateProvider
- type HTTPErrorResponder
- type Option
- type ResponseOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorGRPC ¶
ErrorGRPC tries to map err to errkit.Error and based on result writes standard gRPC error with status statusCode to the response writer.
func ErrorHTTP ¶
ErrorHTTP tries to map err to errkit.Error and based on result writes standard HTTP error with status statusCode to the response writer.
func SetGRPCErrorResponder ¶
func SetGRPCErrorResponder(responder GRPCErrorResponder)
SetGRPCErrorResponder sets the given responder as errGRPCResponder.
func SetHTMLTemplateProvider ¶
func SetHTMLTemplateProvider(templater HTMLTemplateProvider)
SetHTMLTemplateProvider sets the given htmlTemplater as htmlTemplater.
func SetHTTPErrorResponder ¶
func SetHTTPErrorResponder(responder HTTPErrorResponder)
SetHTTPErrorResponder sets the given responder as errHTTPResponder.
func TemplateHTML ¶
TemplateHTML generates an HTML template response for the given name and data. It sets the Content-Type header to "text/html; charset=utf-8" and writes the response with the specified status code. If the template execution fails, an error will be logged and a 500 Internal Server Error response will be sent. Additional options can be passed to modify the response using the Option functions.
Types ¶
type GRPCErrorResponder ¶
GRPCErrorResponder represents a function type that handles and responds to GRPC errors.
type HTMLTemplateProvider ¶
type HTMLTemplateProvider interface { // Template renders the HTML templates by given name. Template(ctx context.Context, name string) (*template.Template, error) }
HTMLTemplateProvider wraps a Template method to render requested HTML template.
type HTTPErrorResponder ¶
type HTTPErrorResponder func(w http.ResponseWriter, err error)
HTTPErrorResponder represents a function which should be called to respond with an error on HTTP call.
type Option ¶
type Option func(o *ResponseOptions)
Option represents a function type that modifies ResponseOptions for an HTTP response.
func WithErrorReport ¶ added in v0.2.19
func WithErrorReport() Option
WithErrorReport is an Option function that will enable error reporting by the errkit.ErrorReporter. Used in
func WithHeader ¶
WithHeader is an Option function that adds the given key-value pair to the headers of the ResponseOptions. The headers are used to modify the headers of an HTTP response.
func WithStatus ¶
WithStatus sets the given status code as the statusCode field of the ResponseOptions parameter.
type ResponseOptions ¶
type ResponseOptions struct {
// contains filtered or unexported fields
}
ResponseOptions represents the options for an HTTP response.
func Options ¶
func Options(w http.ResponseWriter, options ...Option) *ResponseOptions
Options returns a pointer to a new ResponseOptions object with default values and applies the given options to it.