-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.go
More file actions
93 lines (81 loc) · 2.87 KB
/
types.go
File metadata and controls
93 lines (81 loc) · 2.87 KB
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
package celeris
import "time"
// HandlerFunc defines the handler used by middleware and routes.
// Returning a non-nil error propagates it up through the middleware chain.
// The routerAdapter safety net writes an appropriate response for unhandled errors.
type HandlerFunc func(*Context) error
// DefaultMaxFormSize is the default maximum memory used for multipart form
// parsing (32 MB), matching net/http.
const DefaultMaxFormSize int64 = 32 << 20
// maxBodySize is the maximum request/response body size (100 MB), shared by
// stream responses (File, Stream), bridge adapter output, and ToHandler input.
const maxBodySize = 100 << 20
const maxStreamBodySize = maxBodySize
// SameSite controls the SameSite attribute of a cookie.
type SameSite int
const (
// SameSiteDefaultMode leaves the SameSite attribute unset (browser default).
SameSiteDefaultMode SameSite = iota
// SameSiteLaxMode sets SameSite=Lax (cookies sent with top-level navigations).
SameSiteLaxMode
// SameSiteStrictMode sets SameSite=Strict (cookies sent only in first-party context).
SameSiteStrictMode
// SameSiteNoneMode sets SameSite=None (requires Secure; cookies sent in all contexts).
SameSiteNoneMode
)
// String returns the SameSite attribute value ("Lax", "Strict", "None", or "").
func (s SameSite) String() string {
switch s {
case SameSiteLaxMode:
return "Lax"
case SameSiteStrictMode:
return "Strict"
case SameSiteNoneMode:
return "None"
default:
return ""
}
}
// Cookie represents an HTTP cookie for use with Context.SetCookie.
type Cookie struct {
// Name is the cookie name.
Name string
// Value is the cookie value.
Value string
// Path limits the scope of the cookie to the given URL path.
Path string
// Domain limits the scope of the cookie to the given domain.
Domain string
// MaxAge=0 means no Max-Age attribute is sent. Negative value means
// delete the cookie (Max-Age=0 in the header).
MaxAge int
// Expires sets the Expires attribute for legacy client compatibility
// (e.g. IE11). Zero value means no Expires is sent. Prefer MaxAge
// for modern clients.
Expires time.Time
// Secure flags the cookie for HTTPS-only transmission.
Secure bool
// HTTPOnly prevents client-side scripts from accessing the cookie.
HTTPOnly bool
// SameSite controls cross-site request cookie behavior.
SameSite SameSite
}
// Param is a single URL parameter consisting of a key and a value.
type Param struct {
// Key is the parameter name from the route pattern (e.g. "id" from ":id").
Key string
// Value is the matched segment from the request path (e.g. "42").
Value string
}
// Params is a slice of Param.
type Params []Param
// Get returns the value of the first Param matching the given key.
// Returns empty string and false if the key is not found.
func (ps Params) Get(key string) (string, bool) {
for _, p := range ps {
if p.Key == key {
return p.Value, true
}
}
return "", false
}