-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroute_types.go
97 lines (76 loc) · 2.23 KB
/
route_types.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package gz
import (
"net/http"
)
// Route is a definition of a route
type Route struct {
// Name of the route
Name string `json:"name"`
// Description of the route
Description string `json:"description"`
// URI pattern
URI string `json:"uri"`
// Headers required by the route
Headers []Header `json:"headers"`
// HTTP methods supported by the route
Methods Methods `json:"methods"`
// Secure HTTP methods supported by the route
SecureMethods SecureMethods `json:"secure_methods"`
}
// Routes is an array of Route
type Routes []Route
// Header stores the information about headers included in a request.
type Header struct {
Name string `json:"name"`
HeaderDetails Detail `json:"details"`
}
// Detail stores information about a paramter.
type Detail struct {
Type string `json:"type"`
Description string `json:"description"`
Required bool `json:"required"`
}
// Method associates an HTTP method (GET, POST, PUT, DELETE) with a list of
// handlers.
type Method struct {
// GET, POST, PUT, DELETE
// \todo: Make this an enum
Type string `json:"type"`
// Description of the method
Description string `json:"description"`
// A slice of hanlders used to process this method.
Handlers FormatHandlers `json:"handler"`
}
// Methods is a slice of Method.
type Methods []Method
// SecureMethods is a slice of Method that require authentication.
type SecureMethods []Method
// FormatHandler represents a format type string, and handler function pair. Handlers are called in response to a route request.
type FormatHandler struct {
// Format (eg: .json, .proto, .html)
Extension string `json:"extension"`
// Processor for the url pattern
Handler http.Handler `json:"-"`
}
// FormatHandlers is a slice of FormatHandler values.
type FormatHandlers []FormatHandler
// AuthHeadersRequired is an array of Headers needed when authentication is
// required.
var AuthHeadersRequired = []Header{
{
Name: "authorization: Bearer <YOUR_JWT_TOKEN>",
HeaderDetails: Detail{
Required: true,
},
},
}
// AuthHeadersOptional is an array of Headers needed when authentication is
// optional.
var AuthHeadersOptional = []Header{
{
Name: "authorization: Bearer <YOUR_JWT_TOKEN>",
HeaderDetails: Detail{
Required: false,
},
},
}