herodot

package
v0.4.2-alpha.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2016 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const RequestIDKey key = 0

Variables

View Source
var (
	ErrNotFound = &Error{
		Err:  errors.New("Not found"),
		Code: http.StatusNotFound,
	}
	ErrUnauthorized = &Error{
		Err:  errors.New("Unauthorized"),
		Code: http.StatusUnauthorized,
	}
	ErrBadRequest = &Error{
		Err:  errors.New("Bad request"),
		Code: http.StatusBadRequest,
	}
	ErrForbidden = &Error{
		Err:  errors.New("Forbidden"),
		Code: http.StatusForbidden,
	}
)

Functions

func Context

func Context(ctx context.Context) context.Context

func NewContext

func NewContext() context.Context

Types

type Error

type Error struct {
	Err  *errors.Error
	Code int
}

func ToError

func ToError(err error) *Error

func (Error) Error

func (e Error) Error() string

type Herodot

type Herodot interface {
	Write(ctx context.Context, w http.ResponseWriter, r *http.Request, e interface{})

	WriteCode(ctx context.Context, w http.ResponseWriter, r *http.Request, code int, e interface{})

	WriteCreated(ctx context.Context, w http.ResponseWriter, r *http.Request, location string, e interface{})

	WriteError(ctx context.Context, w http.ResponseWriter, r *http.Request, err error)

	WriteErrorCode(ctx context.Context, w http.ResponseWriter, r *http.Request, code int, err error)
}

type JSON

type JSON struct {
	Logger logrus.FieldLogger
}

func (*JSON) Write

func (h *JSON) Write(ctx context.Context, w http.ResponseWriter, r *http.Request, e interface{})

func (*JSON) WriteCode

func (h *JSON) WriteCode(ctx context.Context, w http.ResponseWriter, r *http.Request, code int, e interface{})

func (*JSON) WriteCreated

func (h *JSON) WriteCreated(ctx context.Context, w http.ResponseWriter, r *http.Request, location string, e interface{})

func (*JSON) WriteError

func (h *JSON) WriteError(ctx context.Context, w http.ResponseWriter, r *http.Request, err error)

func (*JSON) WriteErrorCode

func (h *JSON) WriteErrorCode(ctx context.Context, w http.ResponseWriter, r *http.Request, code int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL