...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package runtime
16
17 import (
18 "io"
19 "net/http"
20 "net/url"
21 "time"
22
23 "github.com/go-openapi/strfmt"
24 )
25
26
27 type ClientRequestWriterFunc func(ClientRequest, strfmt.Registry) error
28
29
30 func (fn ClientRequestWriterFunc) WriteToRequest(req ClientRequest, reg strfmt.Registry) error {
31 return fn(req, reg)
32 }
33
34
35 type ClientRequestWriter interface {
36 WriteToRequest(ClientRequest, strfmt.Registry) error
37 }
38
39
40
41 type ClientRequest interface {
42 SetHeaderParam(string, ...string) error
43
44 GetHeaderParams() http.Header
45
46 SetQueryParam(string, ...string) error
47
48 SetFormParam(string, ...string) error
49
50 SetPathParam(string, string) error
51
52 GetQueryParams() url.Values
53
54 SetFileParam(string, ...NamedReadCloser) error
55
56 SetBodyParam(interface{}) error
57
58 SetTimeout(time.Duration) error
59
60 GetMethod() string
61
62 GetPath() string
63
64 GetBody() []byte
65
66 GetBodyParam() interface{}
67
68 GetFileParam() map[string][]NamedReadCloser
69 }
70
71
72 type NamedReadCloser interface {
73 io.ReadCloser
74 Name() string
75 }
76
77
78 func NamedReader(name string, rdr io.Reader) NamedReadCloser {
79 rc, ok := rdr.(io.ReadCloser)
80 if !ok {
81 rc = io.NopCloser(rdr)
82 }
83 return &namedReadCloser{
84 name: name,
85 cr: rc,
86 }
87 }
88
89 type namedReadCloser struct {
90 name string
91 cr io.ReadCloser
92 }
93
94 func (n *namedReadCloser) Close() error {
95 return n.cr.Close()
96 }
97 func (n *namedReadCloser) Read(p []byte) (int, error) {
98 return n.cr.Read(p)
99 }
100 func (n *namedReadCloser) Name() string {
101 return n.name
102 }
103
104 type TestClientRequest struct {
105 Headers http.Header
106 Body interface{}
107 }
108
109 func (t *TestClientRequest) SetHeaderParam(name string, values ...string) error {
110 if t.Headers == nil {
111 t.Headers = make(http.Header)
112 }
113 t.Headers.Set(name, values[0])
114 return nil
115 }
116
117 func (t *TestClientRequest) SetQueryParam(_ string, _ ...string) error { return nil }
118
119 func (t *TestClientRequest) SetFormParam(_ string, _ ...string) error { return nil }
120
121 func (t *TestClientRequest) SetPathParam(_ string, _ string) error { return nil }
122
123 func (t *TestClientRequest) SetFileParam(_ string, _ ...NamedReadCloser) error { return nil }
124
125 func (t *TestClientRequest) SetBodyParam(body interface{}) error {
126 t.Body = body
127 return nil
128 }
129
130 func (t *TestClientRequest) SetTimeout(time.Duration) error {
131 return nil
132 }
133
134 func (t *TestClientRequest) GetQueryParams() url.Values { return nil }
135
136 func (t *TestClientRequest) GetMethod() string { return "" }
137
138 func (t *TestClientRequest) GetPath() string { return "" }
139
140 func (t *TestClientRequest) GetBody() []byte { return nil }
141
142 func (t *TestClientRequest) GetBodyParam() interface{} {
143 return t.Body
144 }
145
146 func (t *TestClientRequest) GetFileParam() map[string][]NamedReadCloser {
147 return nil
148 }
149
150 func (t *TestClientRequest) GetHeaderParams() http.Header {
151 return t.Headers
152 }
153
View as plain text