-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinterfaces.go
116 lines (83 loc) · 2.89 KB
/
interfaces.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package hermes
import (
"context"
"github.com/valyala/fasthttp"
)
// Request is used to retrieve data from an HTTP request
type Request interface {
// Path returns the path of the current URL
Path() []byte
// Method returns the HTTP method
Method() []byte
// IsJSON return weather request body is application/json
IsJSON() bool
// WantsJSON return weather request accepts application/json
WantsJSON() bool
// URI returns the raw URI
URI() *fasthttp.URI
// Header return a header value by name. If the header is not found
// an empty string will be returned.
Header(name string) []byte
// Host returns the host of the request.
Host() []byte
// Param grabs route param by name
Param(name string) string
// Query grabs input from the query string by name
Query(name string) []byte
// QueryMulti grabs multiple input from the query string by name
QueryMulti(name string) [][]byte
// Data unmarshals request body to dst
Data(dst interface{}) error
// Post grabs input from the post data by name
Post(name string) []byte
// PostMulti grabs multiple input from the post data by name
PostMulti(name string) [][]byte
// Cookie grabs input from cookies by name
Cookie(name string) []byte
// Context returns the context.Context of the current request
Context() context.Context
// WithContext returns a shallow copy of the request with a new context
WithContext(ctx context.Context) Request
// Raw returns the fasthttp.RequestCtx of the current request
Raw() *fasthttp.RequestCtx
}
// Response is used to send data to the client
type Response interface {
// Cookie sets an HTTP cookie on the response
// See also `fasthttp.AcquireCookie`
Cookie(cookie *fasthttp.Cookie) Response
// Status sets the HTTP status code of the response. This can only be called once.
Status(status int) Response
// Header adds an HTTP header to the response
Header(name, value string) Response
// Data responds with data provided
//
// Most types will converted to a string representation except structs,
// arrays and maps which will be serialized to JSON.
Data(data interface{}) Result
// Error sends the default 500 response
Error(error, ...interface{}) Result
File(filepath string) Result
FileDownload(filepath, filename string) Result
// Redirect redirects the client to a URL
Redirect(uri string, code int) Result
// End ends the response chain
End() Result
}
// Result is used to finish a request
type Result interface {
Data(data interface{}) Result
Error(error) Result
Redirect(uri string, code int) Result
File(filepath string) Result
FileDownload(filepath, filename string) Result
// End release the resources
End()
}
type Handler func(req Request, res Response) Result
// Middleware is an interface for adding middleware to a Router instance
type Middleware func(req Request, res Response, next Handler) Result
type Router interface {
Routable
Handler() fasthttp.RequestHandler
}