-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathengine_test.go
More file actions
116 lines (105 loc) · 3.72 KB
/
Copy pathengine_test.go
File metadata and controls
116 lines (105 loc) · 3.72 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package engine_test
import (
"context"
"io"
"net/http"
"net/url"
"github.com/go-amwk/core"
)
type Application struct {
handlers []core.HandlerFunc
}
func NewApplication() *Application {
return &Application{
handlers: make([]core.HandlerFunc, 0),
}
}
func (a *Application) Start() error { return nil }
func (a *Application) Use(handlers ...core.HandlerFunc) core.Application {
a.handlers = append(a.handlers, handlers...)
return a
}
func (a *Application) Close() error { return nil }
func (a *Application) Shutdown(ctx context.Context) error { return nil }
type Request struct {
body io.ReadCloser
clientIP string
contentLength int64
cookies []*http.Cookie
ctx context.Context
headers http.Header
method string
protocol string
path string
pathValues map[string]string
resource string
queryValues url.Values
}
func NewRequest() *Request {
return &Request{
body: nil,
clientIP: "127.0.0.1",
contentLength: 123,
cookies: []*http.Cookie{},
ctx: context.Background(),
headers: make(http.Header),
method: "GET",
protocol: "HTTP/1.1",
path: "/test",
pathValues: make(map[string]string),
queryValues: make(url.Values),
}
}
func (r *Request) Body() (io.ReadCloser, error) { return r.body, nil }
func (r *Request) ClientIP() string { return r.clientIP }
func (r *Request) ContentLength() int64 { return r.contentLength }
func (r *Request) Cookie(name string) (*http.Cookie, error) {
for _, c := range r.cookies {
if c.Name == name {
return c, nil
}
}
return nil, http.ErrNoCookie
}
func (r *Request) Cookies() []*http.Cookie { return r.cookies }
func (r *Request) Context() context.Context { return r.ctx }
func (r *Request) Header(name string) string { return r.headers.Get(name) }
func (r *Request) HeaderValues(name string) []string { return r.headers.Values(name) }
func (r *Request) Headers() http.Header { return r.headers }
func (r *Request) Method() string { return r.method }
func (r *Request) Protocol() string { return r.protocol }
func (r *Request) Path() string { return r.path }
func (r *Request) PathValue(key string) string { return r.pathValues[key] }
func (r *Request) SetPathValue(key, value string) {
r.pathValues[key] = value
}
func (r *Request) Resource() string { return r.resource }
func (r *Request) SetResource(resource string) { r.resource = resource }
func (r *Request) Query(key string) string { return r.queryValues.Get(key) }
func (r *Request) QueryValues(key string) []string { return r.queryValues[key] }
func (r *Request) Queries() url.Values { return r.queryValues }
func (r *Request) Request() any { return r }
type Response struct {
headers http.Header
statusCode int
body []byte
}
func NewResponse() *Response {
return &Response{
headers: make(http.Header),
statusCode: 200,
body: make([]byte, 0),
}
}
func (r *Response) AddHeader(key, value string) { r.headers.Add(key, value) }
func (r *Response) SetHeader(key, value string) { r.headers.Set(key, value) }
func (r *Response) GetHeader(key string) string { return r.headers.Get(key) }
func (r *Response) DelHeader(key string) { r.headers.Del(key) }
func (r *Response) Headers() http.Header { return r.headers }
func (r *Response) Write(d []byte) (int, error) {
r.body = append(r.body, d...)
return len(d), nil
}
func (r *Response) Status(code int) { r.statusCode = code }
func (r *Response) StatusCode() int { return r.statusCode }
func (r *Response) Response() any { return r }