-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmethods.go
102 lines (92 loc) · 1.72 KB
/
methods.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
98
99
100
101
102
package gimlet
import "net/http"
type httpMethod int
// Typed constants for specifying HTTP method types on routes.
const (
get httpMethod = iota
put
post
del
patch
head
options
)
func (m httpMethod) String() string {
switch m {
case get:
return http.MethodGet
case put:
return http.MethodPut
case del:
return http.MethodDelete
case patch:
return http.MethodPatch
case post:
return http.MethodPost
case head:
return http.MethodHead
case options:
return http.MethodOptions
default:
return ""
}
}
// OutputFormat enumerates output formats for response writers.
type OutputFormat int
// Enumerations of supported output formats used by gimlet rendering
// facilities.
const (
JSON OutputFormat = iota
TEXT
HTML
YAML
BINARY
CSV
)
// IsValid provides a predicate to validate OutputFormat values.
func (o OutputFormat) IsValid() bool {
switch o {
case JSON, TEXT, HTML, BINARY, YAML, CSV:
return true
default:
return false
}
}
func (o OutputFormat) String() string {
switch o {
case JSON:
return "json"
case TEXT:
return "text"
case HTML:
return "html"
case BINARY:
return "binary"
case YAML:
return "yaml"
case CSV:
return "csv"
default:
return "text"
}
}
// ContentType returns a mime content-type string for output formats
// produced by gimlet's rendering.
func (o OutputFormat) ContentType() string {
switch o {
case JSON:
return "application/json; charset=utf-8"
case TEXT:
return "text/plain; charset=utf-8"
case HTML:
return "application/html; charset=utf-8"
case BINARY:
return "application/octet-stream"
case YAML:
return "application/yaml; charset=utf-8"
case CSV:
return "application/csv; charset=utf-8"
default:
return "text/plain; charset=utf-8"
}
}