wrapped_body.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2019, OpenCensus Authors
  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 ochttp
  15. import (
  16. "io"
  17. )
  18. // wrappedBody returns a wrapped version of the original
  19. // Body and only implements the same combination of additional
  20. // interfaces as the original.
  21. func wrappedBody(wrapper io.ReadCloser, body io.ReadCloser) io.ReadCloser {
  22. var (
  23. wr, i0 = body.(io.Writer)
  24. )
  25. switch {
  26. case !i0:
  27. return struct {
  28. io.ReadCloser
  29. }{wrapper}
  30. case i0:
  31. return struct {
  32. io.ReadCloser
  33. io.Writer
  34. }{wrapper, wr}
  35. default:
  36. return struct {
  37. io.ReadCloser
  38. }{wrapper}
  39. }
  40. }