-
Notifications
You must be signed in to change notification settings - Fork 85
/
request.go
66 lines (56 loc) · 2.06 KB
/
request.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
package http
import (
"net/http"
"github.com/goravel/framework/contracts/filesystem"
"github.com/goravel/framework/contracts/validation"
)
//go:generate mockery --name=Request
type Request interface {
Header(key string, defaultValue ...string) string
Headers() http.Header
Method() string
Path() string
Url() string
FullUrl() string
Ip() string
Host() string
// All Retrieve json, form and query
All() map[string]any
// Bind Retrieve json and bind to obj
Bind(obj any) error
// Route Retrieve an input item from the request: /users/{id}
Route(key string) string
RouteInt(key string) int
RouteInt64(key string) int64
// Query Retrieve a query string item form the request: /users?id=1
Query(key string, defaultValue ...string) string
QueryInt(key string, defaultValue ...int) int
QueryInt64(key string, defaultValue ...int64) int64
QueryBool(key string, defaultValue ...bool) bool
QueryArray(key string) []string
QueryMap(key string) map[string]string
Queries() map[string]string
// DEPRECATED: Use input instead. Retrieve a form string item from the post: /users POST:id=1,
Form(key string, defaultValue ...string) string
// DEPRECATED: Use input instead. Retrieve data from the post: /users JSON:{"id": 1}
Json(key string, defaultValue ...string) string
// Input Retrieve data by order: json, form, query, route
Input(key string, defaultValue ...string) string
InputInt(key string, defaultValue ...int) int
InputInt64(key string, defaultValue ...int64) int64
InputBool(key string, defaultValue ...bool) bool
File(name string) (filesystem.File, error)
AbortWithStatus(code int)
AbortWithStatusJson(code int, jsonObj any)
Next()
Origin() *http.Request
Validate(rules map[string]string, options ...validation.Option) (validation.Validator, error)
ValidateRequest(request FormRequest) (validation.Errors, error)
}
type FormRequest interface {
Authorize(ctx Context) error
Rules(ctx Context) map[string]string
Messages(ctx Context) map[string]string
Attributes(ctx Context) map[string]string
PrepareForValidation(ctx Context, data validation.Data) error
}