Documentation ¶
Index ¶
- Constants
- Variables
- func JSON(name string, fn func(*http.Request) (interface{}, bool, error)) http.Handler
- func Logging(handler http.Handler) http.Handler
- func NotFound(err error) http.Handler
- func Ok() http.Handler
- func Recovery(handler http.Handler) http.Handler
- func RequestDebugging(handler http.Handler) http.Handler
- func ServerError(err error) http.Handler
- func Timeout(dur time.Duration, fn func() (interface{}, bool, error)) (interface{}, bool, error)
- func ValidatePresence(f string, i interface{}) error
- func WriteJSON(status int, obj interface{}) http.Handler
- func WritePB(status int, obj proto.Message) http.Handler
- type Error
- type ErrorHandler
- type Errors
- type Middleware
- type Params
- type Response
- type Router
- type ServiceUnavailableError
- type TimeoutError
- type ValidationError
- type ValidationErrors
- type Validator
Constants ¶
View Source
const ( HEADER_CONTENT_TYPE = "Content-Type" HEADER_CONTENT_LENGTH = "Content-Length" CONTENT_TYPE_JSON = "application/json" CONTENT_TYPE_PROTOBUF = "application/x-protobuf" ERROR_NOT_FOUND = "not found" )
Variables ¶
View Source
var Logger = logger.NewDefaultLogger("service")
View Source
var OK = map[string]string{"status": "ok"}
Functions ¶
func RequestDebugging ¶
Request dumping middleware
func ServerError ¶
func ValidatePresence ¶
Types ¶
type ErrorHandler ¶
type Errors ¶
type Errors struct {
Errors ValidationErrors `json:"errors"`
}
type Response ¶
type Response interface { http.ResponseWriter Status() int Written() bool }
func NewResponse ¶
func NewResponse(rw http.ResponseWriter) Response
type Router ¶
type Router struct { NotFound ErrorHandler ServerError ErrorHandler // contains filtered or unexported fields }
func (*Router) AddMiddleware ¶
func (r *Router) AddMiddleware(h Middleware)
func (*Router) ListenAndServe ¶
type ServiceUnavailableError ¶
type ServiceUnavailableError struct {
}func (ServiceUnavailableError) Error ¶
func (e ServiceUnavailableError) Error() string
type TimeoutError ¶
func (TimeoutError) Error ¶
func (e TimeoutError) Error() string
type ValidationError ¶
type ValidationError struct { Code string `json:"code"` Field string `json:"field"` Title string `json:"title"` }
func (ValidationError) Error ¶
func (e ValidationError) Error() string
type ValidationErrors ¶
type ValidationErrors []ValidationError
func (ValidationErrors) Error ¶
func (es ValidationErrors) Error() string
Source Files ¶
Click to show internal directories.
Click to hide internal directories.