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 runtime16
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) error28
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) error37}
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) error43
44GetHeaderParams() http.Header45
46SetQueryParam(string, ...string) error47
48SetFormParam(string, ...string) error49
50SetPathParam(string, string) error51
52GetQueryParams() url.Values53
54SetFileParam(string, ...NamedReadCloser) error55
56SetBodyParam(interface{}) error57
58SetTimeout(time.Duration) error59
60GetMethod() string61
62GetPath() string63
64GetBody() []byte65
66GetBodyParam() interface{}67
68GetFileParam() map[string][]NamedReadCloser69}
70
71// NamedReadCloser represents a named ReadCloser interface
72type NamedReadCloser interface {73io.ReadCloser74Name() string75}
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 string91cr io.ReadCloser92}
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.name102}
103
104type TestClientRequest struct {105Headers http.Header106Body 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 nil115}
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 = body127return nil128}
129
130func (t *TestClientRequest) SetTimeout(time.Duration) error {131return nil132}
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.Body144}
145
146func (t *TestClientRequest) GetFileParam() map[string][]NamedReadCloser {147return nil148}
149
150func (t *TestClientRequest) GetHeaderParams() http.Header {151return t.Headers152}
153