-
Notifications
You must be signed in to change notification settings - Fork 0
/
constants.go
39 lines (32 loc) · 1.21 KB
/
constants.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package rest
import (
"errors"
"net/http"
"github.com/julienschmidt/httprouter"
)
// HTTP errors
var (
ErrBadRequest = errors.New("400")
ErrUnauthorized = errors.New("401")
ErrNotFound = errors.New("404")
ErrConflict = errors.New("409")
ErrUnprocessableEntity = errors.New("422")
)
// HTTPErrorStatus is the struct that user will receive as body. It can contain a reason
// if we are controlling what to explain about the error.
type HTTPErrorStatus struct {
Code int `json:"code"`
Message string `json:"message"`
Reason string `json:"reason,omitempty"`
ValidationErrors map[string]string `json:"validation_errors,omitempty"`
}
// APIEndpoint is the struct that holds the Handler and Matchers (if any) to build the router
type APIEndpoint struct {
Handler APIHandler
Matcher APIMatcher
}
// APIHandler defines the handler function that will be used for each API endpoint
type APIHandler func(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
// APIMatcher is an array of rules that must be applied for each request to ensure
// the required input is being passed to the API
type APIMatcher []string