Documentation ¶
Overview ¶
Package impart provides a simple interface for a JSON-based API. It is designed for passing errors around a web application, sending back a status code and error message if needed, or a status code and some data on success.
Index ¶
- func RenderActivityJSON(w http.ResponseWriter, value interface{}, status int) error
- func ReqJSON(r *http.Request) bool
- func WriteError(w http.ResponseWriter, e HTTPError) error
- func WriteOAuthError(w http.ResponseWriter, e HTTPError) error
- func WriteRedirect(w http.ResponseWriter, e HTTPError) int
- func WriteSuccess(w http.ResponseWriter, data interface{}, status int) error
- type Envelope
- type HTTPError
- type PlainErrEnvelope
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RenderActivityJSON ¶
func RenderActivityJSON(w http.ResponseWriter, value interface{}, status int) error
func ReqJSON ¶
ReqJSON returns whether or not the given Request is sending JSON, based on the Content-Type header being application/json.
func WriteError ¶
func WriteError(w http.ResponseWriter, e HTTPError) error
WriteError writes the error to the ResponseWriter as JSON.
func WriteOAuthError ¶ added in v1.1.1
func WriteOAuthError(w http.ResponseWriter, e HTTPError) error
WriteOAuthError writes the error to the ResponseWriter as JSON.
func WriteRedirect ¶
func WriteRedirect(w http.ResponseWriter, e HTTPError) int
WriteRedirect sends a redirect
func WriteSuccess ¶
func WriteSuccess(w http.ResponseWriter, data interface{}, status int) error
WriteSuccess writes the successful data and metadata to the ResponseWriter as JSON.
Types ¶
type Envelope ¶
type Envelope struct { Code int `json:"code"` ErrorType string `json:"error_type,omitempty"` ErrorMessage string `json:"error_msg,omitempty"` Data interface{} `json:"data,omitempty"` }
Envelope contains metadata and optional data for a response object. Responses will always contain a status code and either: - response Data on a 2xx response, or - an ErrorMessage on non-2xx responses
ErrorType is not currently used.
type PlainErrEnvelope ¶ added in v1.1.1
type PlainErrEnvelope struct {
Error string `json:"error"`
}