本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.4KB

  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. package runtime
  15. import (
  16. "io"
  17. "io/ioutil"
  18. "net/http"
  19. "net/url"
  20. "time"
  21. "github.com/go-openapi/strfmt"
  22. )
  23. // ClientRequestWriterFunc converts a function to a request writer interface
  24. type ClientRequestWriterFunc func(ClientRequest, strfmt.Registry) error
  25. // WriteToRequest adds data to the request
  26. func (fn ClientRequestWriterFunc) WriteToRequest(req ClientRequest, reg strfmt.Registry) error {
  27. return fn(req, reg)
  28. }
  29. // ClientRequestWriter is an interface for things that know how to write to a request
  30. type ClientRequestWriter interface {
  31. WriteToRequest(ClientRequest, strfmt.Registry) error
  32. }
  33. // ClientRequest is an interface for things that know how to
  34. // add information to a swagger client request
  35. type ClientRequest interface {
  36. SetHeaderParam(string, ...string) error
  37. GetHeaderParams() http.Header
  38. SetQueryParam(string, ...string) error
  39. SetFormParam(string, ...string) error
  40. SetPathParam(string, string) error
  41. GetQueryParams() url.Values
  42. SetFileParam(string, ...NamedReadCloser) error
  43. SetBodyParam(interface{}) error
  44. SetTimeout(time.Duration) error
  45. GetMethod() string
  46. GetPath() string
  47. GetBody() []byte
  48. GetBodyParam() interface{}
  49. GetFileParam() map[string][]NamedReadCloser
  50. }
  51. // NamedReadCloser represents a named ReadCloser interface
  52. type NamedReadCloser interface {
  53. io.ReadCloser
  54. Name() string
  55. }
  56. // NamedReader creates a NamedReadCloser for use as file upload
  57. func NamedReader(name string, rdr io.Reader) NamedReadCloser {
  58. rc, ok := rdr.(io.ReadCloser)
  59. if !ok {
  60. rc = ioutil.NopCloser(rdr)
  61. }
  62. return &namedReadCloser{
  63. name: name,
  64. cr: rc,
  65. }
  66. }
  67. type namedReadCloser struct {
  68. name string
  69. cr io.ReadCloser
  70. }
  71. func (n *namedReadCloser) Close() error {
  72. return n.cr.Close()
  73. }
  74. func (n *namedReadCloser) Read(p []byte) (int, error) {
  75. return n.cr.Read(p)
  76. }
  77. func (n *namedReadCloser) Name() string {
  78. return n.name
  79. }
上海开阖软件有限公司 沪ICP备12045867号-1