herodot: github.com/ory/herodot Index | Files

package herodot

import "github.com/ory/herodot"

* Copyright © 2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @author Aeneas Rekkas <aeneas+oss@aeneas.io> * @copyright 2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io> * @license Apache-2.0

* Copyright © 2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @author Aeneas Rekkas <aeneas+oss@aeneas.io> * @copyright 2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io> * @license Apache-2.0

* Copyright © 2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @author Aeneas Rekkas <aeneas+oss@aeneas.io> * @copyright 2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io> * @license Apache-2.0

* Copyright © 2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @author Aeneas Rekkas <aeneas+oss@aeneas.io> * @copyright 2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io> * @license Apache-2.0

Index

Package Files

error.go error_assert.go error_default.go error_defaults.go error_reporter.go json.go negotiator.go plain.go writer.go

Variables

var ErrBadRequest = DefaultError{
    StatusField: http.StatusText(http.StatusBadRequest),
    ErrorField:  "The request was malformed or contained invalid parameters",
    CodeField:   http.StatusBadRequest,
}
var ErrConflict = DefaultError{
    StatusField: http.StatusText(http.StatusConflict),
    ErrorField:  "The resource could not be created due to a conflict",
    CodeField:   http.StatusConflict,
}
var ErrForbidden = DefaultError{
    StatusField: http.StatusText(http.StatusForbidden),
    ErrorField:  "The requested action was forbidden",
    CodeField:   http.StatusForbidden,
}
var ErrInternalServerError = DefaultError{
    StatusField: http.StatusText(http.StatusInternalServerError),
    ErrorField:  "An internal server error occurred, please contact the system administrator",
    CodeField:   http.StatusInternalServerError,
}
var ErrNotFound = DefaultError{
    StatusField: http.StatusText(http.StatusNotFound),
    ErrorField:  "The requested resource could not be found",
    CodeField:   http.StatusNotFound,
}
var ErrUnauthorized = DefaultError{
    StatusField: http.StatusText(http.StatusUnauthorized),
    ErrorField:  "The request could not be authorized",
    CodeField:   http.StatusUnauthorized,
}
var ErrUnsupportedMediaType = DefaultError{
    StatusField: http.StatusText(http.StatusUnsupportedMediaType),
    ErrorField:  "The request is using an unknown content type",
    CodeField:   http.StatusUnsupportedMediaType,
}

func DefaultErrorLogger Uses

func DefaultErrorLogger(logger logrus.FieldLogger, err error) logrus.FieldLogger

func DefaultErrorReporter Uses

func DefaultErrorReporter(logger logrus.FieldLogger, args ...interface{}) func(w http.ResponseWriter, r *http.Request, code int, err error)

type DefaultError Uses

type DefaultError struct {
    CodeField    int                    `json:"code,omitempty"`
    StatusField  string                 `json:"status,omitempty"`
    RIDField     string                 `json:"request,omitempty"`
    ReasonField  string                 `json:"reason,omitempty"`
    DebugField   string                 `json:"debug,omitempty"`
    DetailsField map[string]interface{} `json:"details,omitempty"`
    ErrorField   string                 `json:"message"`
    // contains filtered or unexported fields
}

func ToDefaultError Uses

func ToDefaultError(err error, id string) *DefaultError

func (*DefaultError) Debug Uses

func (e *DefaultError) Debug() string

func (*DefaultError) Details Uses

func (e *DefaultError) Details() map[string]interface{}

func (*DefaultError) Error Uses

func (e *DefaultError) Error() string

func (*DefaultError) Format Uses

func (e *DefaultError) Format(s fmt.State, verb rune)

func (*DefaultError) Reason Uses

func (e *DefaultError) Reason() string

func (*DefaultError) RequestID Uses

func (e *DefaultError) RequestID() string

func (*DefaultError) StackTrace Uses

func (e *DefaultError) StackTrace() errors.StackTrace

StackTrace returns the error's stack trace.

func (*DefaultError) Status Uses

func (e *DefaultError) Status() string

func (*DefaultError) StatusCode Uses

func (e *DefaultError) StatusCode() int

func (*DefaultError) WithDebug Uses

func (e *DefaultError) WithDebug(debug string) *DefaultError

func (*DefaultError) WithDebugf Uses

func (e *DefaultError) WithDebugf(debug string, args ...interface{}) *DefaultError

func (*DefaultError) WithDetail Uses

func (e *DefaultError) WithDetail(key, detail string) *DefaultError

func (*DefaultError) WithDetailf Uses

func (e *DefaultError) WithDetailf(key string, message string, args ...interface{}) *DefaultError

func (*DefaultError) WithError Uses

func (e *DefaultError) WithError(message string) *DefaultError

func (*DefaultError) WithErrorf Uses

func (e *DefaultError) WithErrorf(message string, args ...interface{}) *DefaultError

func (*DefaultError) WithReason Uses

func (e *DefaultError) WithReason(reason string) *DefaultError

func (*DefaultError) WithReasonf Uses

func (e *DefaultError) WithReasonf(reason string, args ...interface{}) *DefaultError

func (*DefaultError) WithTrace Uses

func (e *DefaultError) WithTrace(err error) *DefaultError

type JSONWriter Uses

type JSONWriter struct {
    Reporter      reporter
    ErrorEnhancer func(r *http.Request, err error) interface{}
    // contains filtered or unexported fields
}

json outputs JSON.

func NewJSONWriter Uses

func NewJSONWriter(logger logrus.FieldLogger) *JSONWriter

NewJSONWriter returns a json

func (*JSONWriter) Write Uses

func (h *JSONWriter) Write(w http.ResponseWriter, r *http.Request, e interface{})

Write a response object to the ResponseWriter with status code 200.

func (*JSONWriter) WriteCode Uses

func (h *JSONWriter) WriteCode(w http.ResponseWriter, r *http.Request, code int, e interface{})

WriteCode writes a response object to the ResponseWriter and sets a response code.

func (*JSONWriter) WriteCreated Uses

func (h *JSONWriter) WriteCreated(w http.ResponseWriter, r *http.Request, location string, e interface{})

WriteCreated writes a response object to the ResponseWriter with status code 201 and the Location header set to location.

func (*JSONWriter) WriteError Uses

func (h *JSONWriter) WriteError(w http.ResponseWriter, r *http.Request, err interface{})

WriteError writes an error to ResponseWriter and tries to extract the error's status code by asserting statusCodeCarrier. If the error does not implement statusCodeCarrier, the status code is set to 500.

func (*JSONWriter) WriteErrorCode Uses

func (h *JSONWriter) WriteErrorCode(w http.ResponseWriter, r *http.Request, code int, err interface{})

WriteErrorCode writes an error to ResponseWriter and forces an error code.

type NegotiationHandler Uses

type NegotiationHandler struct {
    // contains filtered or unexported fields
}

NegotiationHandler automatically negotiates the content type with the request client.

func NewNegotiationHandler Uses

func NewNegotiationHandler(logger logrus.FieldLogger) *NegotiationHandler

NewNegotiationHandler creates a new NewNegotiationHandler.

func (*NegotiationHandler) Write Uses

func (h *NegotiationHandler) Write(w http.ResponseWriter, r *http.Request, e interface{})

Write a response object to the ResponseWriter with status code 200.

func (*NegotiationHandler) WriteCode Uses

func (h *NegotiationHandler) WriteCode(w http.ResponseWriter, r *http.Request, code int, e interface{})

WriteCode writes a response object to the ResponseWriter and sets a response code.

func (*NegotiationHandler) WriteCreated Uses

func (h *NegotiationHandler) WriteCreated(w http.ResponseWriter, r *http.Request, location string, e interface{})

WriteCreated writes a response object to the ResponseWriter with status code 201 and the Location header set to location.

func (*NegotiationHandler) WriteError Uses

func (h *NegotiationHandler) WriteError(w http.ResponseWriter, r *http.Request, err interface{})

WriteError writes an error to ResponseWriter and tries to extract the error's status code by asserting statusCodeCarrier. If the error does not implement statusCodeCarrier, the status code is set to 500.

func (*NegotiationHandler) WriteErrorCode Uses

func (h *NegotiationHandler) WriteErrorCode(w http.ResponseWriter, r *http.Request, code int, err interface{})

WriteErrorCode writes an error to ResponseWriter and forces an error code.

type TextWriter Uses

type TextWriter struct {
    Reporter reporter
    // contains filtered or unexported fields
}

json outputs JSON.

func NewTextWriter Uses

func NewTextWriter(logger logrus.FieldLogger, contentType string) *TextWriter

NewPlainWriter returns a json

func (*TextWriter) Write Uses

func (h *TextWriter) Write(w http.ResponseWriter, r *http.Request, e interface{})

Write a response object to the ResponseWriter with status code 200.

func (*TextWriter) WriteCode Uses

func (h *TextWriter) WriteCode(w http.ResponseWriter, r *http.Request, code int, e interface{})

WriteCode writes a response object to the ResponseWriter and sets a response code.

func (*TextWriter) WriteCreated Uses

func (h *TextWriter) WriteCreated(w http.ResponseWriter, r *http.Request, location string, e interface{})

WriteCreated writes a response object to the ResponseWriter with status code 201 and the Location header set to location.

func (*TextWriter) WriteError Uses

func (h *TextWriter) WriteError(w http.ResponseWriter, r *http.Request, err interface{})

WriteError writes an error to ResponseWriter and tries to extract the error's status code by asserting statusCodeCarrier. If the error does not implement statusCodeCarrier, the status code is set to 500.

func (*TextWriter) WriteErrorCode Uses

func (h *TextWriter) WriteErrorCode(w http.ResponseWriter, r *http.Request, code int, err interface{})

WriteErrorCode writes an error to ResponseWriter and forces an error code.

type Writer Uses

type Writer interface {
    // Write a response object to the ResponseWriter with status code 200.
    Write(w http.ResponseWriter, r *http.Request, e interface{})

    // WriteCode writes a response object to the ResponseWriter and sets a response code.
    WriteCode(w http.ResponseWriter, r *http.Request, code int, e interface{})

    // WriteCreated writes a response object to the ResponseWriter with status code 201 and
    // the Location header set to location.
    WriteCreated(w http.ResponseWriter, r *http.Request, location string, e interface{})

    // WriteError writes an error to ResponseWriter and tries to extract the error's status code by
    // asserting statusCodeCarrier. If the error does not implement statusCodeCarrier, the status code
    // is set to 500.
    WriteError(w http.ResponseWriter, r *http.Request, err interface{})

    // WriteErrorCode writes an error to ResponseWriter and forces an error code.
    WriteErrorCode(w http.ResponseWriter, r *http.Request, code int, err interface{})
}

Writer is a helper to write arbitrary data to a ResponseWriter

Package herodot imports 9 packages (graph) and is imported by 156 packages. Updated 2020-04-09. Refresh now. Tools for package owners.