sebak: boscoin.io/sebak/lib/network/httputils Index | Files

package httputils

import "boscoin.io/sebak/lib/network/httputils"

Index

Package Files

http_problem.go httputils.go json.go

Constants

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

Variables

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,
    }
)

func IsEventStream Uses

func IsEventStream(r *http.Request) bool

IsEventStream checks request header accept is text/event-stream

func MustWriteJSON Uses

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 Uses

func ProblemTypeByCode(code uint) string

func StatusCode Uses

func StatusCode(err error) int

func WriteJSON Uses

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

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

func WriteJSONError Uses

func WriteJSONError(w http.ResponseWriter, err error)

WriteJSONError writes the error to the http response as json encoding

type HALResource Uses

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

type Problem Uses

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 Uses

func NewDetailedStatusProblem(status int, detail string) Problem

func NewErrorProblem Uses

func NewErrorProblem(err error, status int) Problem

func NewProblem Uses

func NewProblem(problemType string, title string) Problem

func NewStatusProblem Uses

func NewStatusProblem(status int) Problem

func (Problem) SetDetail Uses

func (p Problem) SetDetail(detail string) Problem

func (Problem) SetInstance Uses

func (p Problem) SetInstance(instance string) Problem

func (Problem) SetStatus Uses

func (p Problem) SetStatus(status int) Problem

type ResponseWriterInterceptor Uses

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 Uses

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

func (ResponseWriterInterceptor) Header Uses

func (w ResponseWriterInterceptor) Header() http.Header

Satisfy the http.ResponseWriter interface

func (ResponseWriterInterceptor) StatusCode Uses

func (w ResponseWriterInterceptor) StatusCode() int

func (ResponseWriterInterceptor) Write Uses

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

func (*ResponseWriterInterceptor) WriteHeader Uses

func (w *ResponseWriterInterceptor) WriteHeader(statusCode int)

func (ResponseWriterInterceptor) WriteHeaderToOrigin Uses

func (w ResponseWriterInterceptor) WriteHeaderToOrigin(statusCode int)

func (ResponseWriterInterceptor) WriteToOrigin Uses

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

Package httputils imports 6 packages (graph) and is imported by 12 packages. Updated 2019-03-27. Refresh now. Tools for package owners.