httputils

package
v0.0.0-...-8aa4d74 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2019 License: GPL-3.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

View Source
const (
	HttpProblemDefaultType     = "about:blank" // It should be URI
	HttpProblemErrorTypePrefix = "https://boscoin.io/sebak/error/"
)

Variables

Functions

func IsEventStream

func IsEventStream(r *http.Request) bool

IsEventStream checks request header accept is text/event-stream

func MustWriteJSON

func MustWriteJSON(w http.ResponseWriter, code int, v interface{})

MustWriteJSON writes the value or an error of it to the http response as json

func ProblemTypeByCode

func ProblemTypeByCode(code uint) string

func StatusCode

func StatusCode(err error) int

func WriteJSON

func WriteJSON(w http.ResponseWriter, code int, v interface{}) error

WriteJSON writes the value v to the http response as json encoding

func WriteJSONError

func WriteJSONError(w http.ResponseWriter, err error)

WriteJSONError writes the error to the http response as json encoding

Types

type HALResource

type HALResource interface {
	Resource() *hal.Resource
}

type Problem

type Problem struct {
	// "type" (string) - A URI reference [RFC3986] that identifies the
	// problem type.  This specification encourages that, when
	// dereferenced, it provide human-readable documentation for the
	// problem type (e.g., using HTML [W3C.REC-html5-20141028]).  When
	// this member is not present, its value is assumed to be
	// "about:blank".
	Type string `json:"type"`

	//"title" (string) - A short, human-readable summary of the problem
	//type.  It SHOULD NOT change from occurrence to occurrence of the
	//problem, except for purposes of localization (e.g., using
	//proactive content negotiation; see [RFC7231], Section 3.4).
	Title string `json:"title"`

	//"status" (number) - The HTTP status code ([RFC7231], Section 6)
	//generated by the origin server for this occurrence of the problem.
	Status int `json:"status,omitempty"`

	//"detail" (string) - A human-readable explanation specific to this
	//occurrence of the problem.
	Detail string `json:"detail,omitempty"`

	//"instance" (string) - A URI reference that identifies the specific
	//occurrence of the problem.  It may or may not yield further
	//information if dereferenced.
	Instance string `json:"instance,omitempty"`
}

func NewDetailedStatusProblem

func NewDetailedStatusProblem(status int, detail string) Problem

func NewErrorProblem

func NewErrorProblem(err error, status int) Problem

func NewProblem

func NewProblem(problemType string, title string) Problem

func NewStatusProblem

func NewStatusProblem(status int) Problem

func (Problem) SetDetail

func (p Problem) SetDetail(detail string) Problem

func (Problem) SetInstance

func (p Problem) SetInstance(instance string) Problem

func (Problem) SetStatus

func (p Problem) SetStatus(status int) Problem

type ResponseWriterInterceptor

type ResponseWriterInterceptor struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

Create our own ResponseWriterInterceptor to wrap a standard http.ResponseWriter so we can store the status code.

func NewResponseWriterInterceptor

func NewResponseWriterInterceptor(w http.ResponseWriter, writer io.Writer) *ResponseWriterInterceptor

func (ResponseWriterInterceptor) Header

Satisfy the http.ResponseWriter interface

func (ResponseWriterInterceptor) StatusCode

func (w ResponseWriterInterceptor) StatusCode() int

func (ResponseWriterInterceptor) Write

func (w ResponseWriterInterceptor) Write(data []byte) (int, error)

func (*ResponseWriterInterceptor) WriteHeader

func (w *ResponseWriterInterceptor) WriteHeader(statusCode int)

func (ResponseWriterInterceptor) WriteHeaderToOrigin

func (w ResponseWriterInterceptor) WriteHeaderToOrigin(statusCode int)

func (ResponseWriterInterceptor) WriteToOrigin

func (w ResponseWriterInterceptor) WriteToOrigin(data []byte) (int, error)

Jump to

Keyboard shortcuts

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