podman
152 строки · 3.7 Кб
1// Copyright 2015 go-swagger maintainers
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package runtime
16
17import (
18"io"
19"net/http"
20"net/url"
21"time"
22
23"github.com/go-openapi/strfmt"
24)
25
26// ClientRequestWriterFunc converts a function to a request writer interface
27type ClientRequestWriterFunc func(ClientRequest, strfmt.Registry) error
28
29// WriteToRequest adds data to the request
30func (fn ClientRequestWriterFunc) WriteToRequest(req ClientRequest, reg strfmt.Registry) error {
31return fn(req, reg)
32}
33
34// ClientRequestWriter is an interface for things that know how to write to a request
35type ClientRequestWriter interface {
36WriteToRequest(ClientRequest, strfmt.Registry) error
37}
38
39// ClientRequest is an interface for things that know how to
40// add information to a swagger client request
41type ClientRequest interface {
42SetHeaderParam(string, ...string) error
43
44GetHeaderParams() http.Header
45
46SetQueryParam(string, ...string) error
47
48SetFormParam(string, ...string) error
49
50SetPathParam(string, string) error
51
52GetQueryParams() url.Values
53
54SetFileParam(string, ...NamedReadCloser) error
55
56SetBodyParam(interface{}) error
57
58SetTimeout(time.Duration) error
59
60GetMethod() string
61
62GetPath() string
63
64GetBody() []byte
65
66GetBodyParam() interface{}
67
68GetFileParam() map[string][]NamedReadCloser
69}
70
71// NamedReadCloser represents a named ReadCloser interface
72type NamedReadCloser interface {
73io.ReadCloser
74Name() string
75}
76
77// NamedReader creates a NamedReadCloser for use as file upload
78func NamedReader(name string, rdr io.Reader) NamedReadCloser {
79rc, ok := rdr.(io.ReadCloser)
80if !ok {
81rc = io.NopCloser(rdr)
82}
83return &namedReadCloser{
84name: name,
85cr: rc,
86}
87}
88
89type namedReadCloser struct {
90name string
91cr io.ReadCloser
92}
93
94func (n *namedReadCloser) Close() error {
95return n.cr.Close()
96}
97func (n *namedReadCloser) Read(p []byte) (int, error) {
98return n.cr.Read(p)
99}
100func (n *namedReadCloser) Name() string {
101return n.name
102}
103
104type TestClientRequest struct {
105Headers http.Header
106Body interface{}
107}
108
109func (t *TestClientRequest) SetHeaderParam(name string, values ...string) error {
110if t.Headers == nil {
111t.Headers = make(http.Header)
112}
113t.Headers.Set(name, values[0])
114return nil
115}
116
117func (t *TestClientRequest) SetQueryParam(_ string, _ ...string) error { return nil }
118
119func (t *TestClientRequest) SetFormParam(_ string, _ ...string) error { return nil }
120
121func (t *TestClientRequest) SetPathParam(_ string, _ string) error { return nil }
122
123func (t *TestClientRequest) SetFileParam(_ string, _ ...NamedReadCloser) error { return nil }
124
125func (t *TestClientRequest) SetBodyParam(body interface{}) error {
126t.Body = body
127return nil
128}
129
130func (t *TestClientRequest) SetTimeout(time.Duration) error {
131return nil
132}
133
134func (t *TestClientRequest) GetQueryParams() url.Values { return nil }
135
136func (t *TestClientRequest) GetMethod() string { return "" }
137
138func (t *TestClientRequest) GetPath() string { return "" }
139
140func (t *TestClientRequest) GetBody() []byte { return nil }
141
142func (t *TestClientRequest) GetBodyParam() interface{} {
143return t.Body
144}
145
146func (t *TestClientRequest) GetFileParam() map[string][]NamedReadCloser {
147return nil
148}
149
150func (t *TestClientRequest) GetHeaderParams() http.Header {
151return t.Headers
152}
153