Documentation
¶
Index ¶
- Constants
- Variables
- func IsEventStream(r *http.Request) bool
- func MustWriteJSON(w http.ResponseWriter, code int, v interface{})
- func ProblemTypeByCode(code uint) string
- func StatusCode(err error) int
- func WriteJSON(w http.ResponseWriter, code int, v interface{}) error
- func WriteJSONError(w http.ResponseWriter, err error)
- type HALResource
- type Problem
- type ResponseWriterInterceptor
- func (w ResponseWriterInterceptor) Header() http.Header
- func (w ResponseWriterInterceptor) StatusCode() int
- func (w ResponseWriterInterceptor) Write(data []byte) (int, error)
- func (w *ResponseWriterInterceptor) WriteHeader(statusCode int)
- func (w ResponseWriterInterceptor) WriteHeaderToOrigin(statusCode int)
- func (w ResponseWriterInterceptor) WriteToOrigin(data []byte) (int, error)
Constants ¶
View Source
const ( HttpProblemDefaultType = "about:blank" // It should be URI HttpProblemErrorTypePrefix = "https://boscoin.io/sebak/error/" )
Variables ¶
View Source
var ( // ErrorsToStatus defines errors.Error does not have 400 status code. ErrorsToStatus = map[uint]int{ errors.TooManyRequests.Code: http.StatusTooManyRequests, errors.BlockTransactionDoesNotExists.Code: http.StatusNotFound, errors.BlockAccountDoesNotExists.Code: http.StatusNotFound, errors.TransactionPoolFull.Code: http.StatusLocked, errors.BadRequestParameter.Code: http.StatusBadRequest, } )
Functions ¶
func IsEventStream ¶
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 StatusCode ¶
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 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 NewErrorProblem ¶
func NewProblem ¶
func NewStatusProblem ¶
func (Problem) SetInstance ¶
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 ¶
func (w ResponseWriterInterceptor) Header() http.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)
Click to show internal directories.
Click to hide internal directories.