Documentation ¶
Index ¶
- Constants
- Variables
- func APIHeaders(w http.ResponseWriter)
- func NotFoundHandler(w http.ResponseWriter, r *http.Request)
- func RequestLogger(r *http.Request) *logrus.Entry
- func URLParam(r *http.Request, param string, err error) (string, error)
- func UnmarshalRequest(request *http.Request, unmarshalTo interface{}) error
- func WriteCompress(w http.ResponseWriter, r *http.Request, towrite io.Reader, status int) error
- func WriteCompressAsync(w http.ResponseWriter, r *http.Request, towrite io.Reader, status int) error
- func WriteGzipJSON(w http.ResponseWriter, r *http.Request, data interface{}, err error)
- func WriteJSON(w http.ResponseWriter, r *http.Request, data interface{}, err error)
- func WriteJSONError(w http.ResponseWriter, r *http.Request, status int, err error)
- func WriteJSONStatus(w http.ResponseWriter, r *http.Request, data interface{}, status int)
- func WriteResult(w http.ResponseWriter, r *http.Request, err error)
- type AsyncWriter
- type Context
- type ErrorResponse
- type Requester
Constants ¶
const ( // HeedyContext is the context entry used to get the auth context from the request context HeedyContext notABasicType = iota )
Variables ¶
var ErrNotFound = errors.New("not_found: The given endpoint is not available")
var QueryDecoder = schema.NewDecoder()
Functions ¶
func APIHeaders ¶ added in v0.5.1
func APIHeaders(w http.ResponseWriter)
APIHeaders writes headers that need to be present in all API requests
func NotFoundHandler ¶
func NotFoundHandler(w http.ResponseWriter, r *http.Request)
func RequestLogger ¶
RequestLogger generates a basic logger that holds relevant request info
func UnmarshalRequest ¶
UnmarshalRequest unmarshals the input data to the given interface
func WriteCompress ¶
WriteCompress compresses a response Reader object if it has an accepted encoding. While it can be a security risk is some cases, it is very useful when the response can be enormous (like timeseries data).
func WriteCompressAsync ¶
func WriteCompressAsync(w http.ResponseWriter, r *http.Request, towrite io.Reader, status int) error
WriteCompressAsync is identical to WriteCompress, but it does compression in another thread, since gzip is cpu-consuming
func WriteGzipJSON ¶
func WriteGzipJSON(w http.ResponseWriter, r *http.Request, data interface{}, err error)
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, r *http.Request, data interface{}, err error)
WriteJSON writes response as JSON, or writes the error if such is given
func WriteJSONError ¶
WriteJSONError writes an error message as json. It is assumed that the resulting status code is not StatusOK, but rather 4xx
func WriteJSONStatus ¶
func WriteJSONStatus(w http.ResponseWriter, r *http.Request, data interface{}, status int)
WriteJSONStatus writes json with the given status code
func WriteResult ¶
func WriteResult(w http.ResponseWriter, r *http.Request, err error)
WriteResult writes empty object if the command succeeded, and outputs an error if it didn't
Types ¶
type AsyncWriter ¶
func NewAsyncWriter ¶
func NewAsyncWriter(w io.Writer) *AsyncWriter
func (*AsyncWriter) Close ¶
func (aw *AsyncWriter) Close() error
type Context ¶
type Context struct { Requester Log *logrus.Entry // The request's logger DB database.DB // The authenticated database object Events events.Handler // The event handler (must be set here for plugins) RequestID string // The ID of the original query to the API ID string // The ID sent to plugins in X-Heedy-ID header, and is used for all internal requests Plugin string // The plugin that sent the request }
A Context is generated for all requests, and holds all the info necessary for completing it. This object can be extracted from a request with the CTX function.
type ErrorResponse ¶
type ErrorResponse struct { ErrorName string `json:"error"` ErrorDescription string `json:"error_description"` ID string `json:"id,omitempty"` }
ErrorResponse is the response given by the server upon an error
func NewErrorResponse ¶
func NewErrorResponse(err error) ErrorResponse
func (*ErrorResponse) Error ¶
func (er *ErrorResponse) Error() string