Documentation ¶
Index ¶
- Variables
- func ErrorResponse(w http.ResponseWriter, r *http.Request, code int, error error, msg string)
- func GetAddr(r *http.Request) string
- func JsonResponse(w http.ResponseWriter, data interface{})
- func Logger(next http.Handler) http.Handler
- func NotFound(w http.ResponseWriter, _ *http.Request)
- func OkResponse(w http.ResponseWriter)
- func ReadBody(r *http.Request, str interface{}) error
- func Readiness(endpoint string, isReady *atomic.Value) func(http.Handler) http.Handler
- func RenderJSON(w http.ResponseWriter, code int, data interface{})
- func TextResponse(w http.ResponseWriter, data string)
- type HttpError
- type SSLConfig
- type Server
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrUnmarshal = errors.New("UNMARSHAL_ERROR") ErrMissingField = errors.New("MISSING_FIELD") ErrNotFound = errors.New("NOT_FOUND") ErrValidate = errors.New("VALIDATION_ERROR") )
View Source
var ErrEmptyRequest = errors.New("empty request")
View Source
var ErrNotPointer = errors.New("not pointer provided")
Functions ¶
func ErrorResponse ¶
ErrorResponse - write a HttpError structure as response
func JsonResponse ¶
func JsonResponse(w http.ResponseWriter, data interface{})
JsonResponse - write a response with application/json Content-Type header
func NotFound ¶
func NotFound(w http.ResponseWriter, _ *http.Request)
NotFound - return error page for not found
func OkResponse ¶ added in v0.0.7
func OkResponse(w http.ResponseWriter)
OkResponse - write OK response with application/json Content-Type header
func RenderJSON ¶
func RenderJSON(w http.ResponseWriter, code int, data interface{})
RenderJSON sends data as json
func TextResponse ¶ added in v0.0.20
func TextResponse(w http.ResponseWriter, data string)
TextResponse - write a response with application/text Content-Type header
Types ¶
type HttpError ¶
type HttpError struct { Err string `json:"error"` Message string `json:"message,omitempty"` TraceID string `json:"trace_id,omitempty"` }
HttpError - structure for http errors
type Server ¶
type Server struct { Address string Port int IsReady *atomic.Value SSL *SSLConfig ReadHeaderTimeout time.Duration WriteTimeout time.Duration IdleTimeout time.Duration // contains filtered or unexported fields }
Server - rest server struct
Click to show internal directories.
Click to hide internal directories.