Documentation ¶
Overview ¶
This package provides a syntactic sugar and helper functions to make http things easier to read or to express
Index ¶
- func JSONEncode(rw http.ResponseWriter, v interface{}) error
- func JSONEncodeWithCode(rw http.ResponseWriter, v interface{}, statusCode int) error
- func NewClient(timeoutSec time.Duration, skipCertVerification bool) *http.Client
- func NewRenegotiationTLSClient(timeoutSec time.Duration, skipCertVerification bool) *http.Client
- type ErrorDTO
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JSONEncode ¶
func JSONEncode(rw http.ResponseWriter, v interface{}) error
Encode encodes the given object to json format and writes it to given ResponseWriter
func JSONEncodeWithCode ¶
func JSONEncodeWithCode(rw http.ResponseWriter, v interface{}, statusCode int) error
EncodeWithCode encodes the given object to json format and writes it to given ResponseWriter with custom status code
Types ¶
type ErrorDTO ¶
type ErrorDTO struct { // Status is original HTTP error code Status int `json:"status"` // RequestID defines the id of the incoming request RequestID string `json:"requestId"` // Message is descriptive human-readable error Message string `json:"message,omitempty"` // Details about the error Details string `json:"details,omitempty"` }
ErrorDTO represents a json returned in case of error. Only Status and RequestID fields are required.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer provides syntactic sugar for writing http responses. Works in two modes:
- devMode: true - returns a given error in the response under `details` field
- devMode: false - only log the given error in context of the requestID but do not return it in response
func NewResponseWriter ¶
func NewResponseWriter(log logrus.FieldLogger, devMode bool) *Writer
NewResponseWriter returns new instance of Writer
func (*Writer) InternalServerError ¶
func (w *Writer) InternalServerError(rw http.ResponseWriter, r *http.Request, err error, context string)
InternalServerError writes standard InternalServerError response to given ResponseWriter.
Click to show internal directories.
Click to hide internal directories.