client.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package transport
  2. import (
  3. "crypto/tls"
  4. "net/http"
  5. )
  6. // Sender is an interface that clients must implement
  7. // to be able to send requests to a remote connection.
  8. type Sender interface {
  9. // Do sends request to a remote endpoint.
  10. Do(*http.Request) (*http.Response, error)
  11. }
  12. // Client is an interface that abstracts all remote connections.
  13. type Client interface {
  14. Sender
  15. // Secure tells whether the connection is secure or not.
  16. Secure() bool
  17. // Scheme returns the connection protocol the client uses.
  18. Scheme() string
  19. // TLSConfig returns any TLS configuration the client uses.
  20. TLSConfig() *tls.Config
  21. }
  22. // tlsInfo returns information about the TLS configuration.
  23. type tlsInfo struct {
  24. tlsConfig *tls.Config
  25. }
  26. // TLSConfig returns the TLS configuration.
  27. func (t *tlsInfo) TLSConfig() *tls.Config {
  28. return t.tlsConfig
  29. }
  30. // Scheme returns protocol scheme to use.
  31. func (t *tlsInfo) Scheme() string {
  32. if t.tlsConfig != nil {
  33. return "https"
  34. }
  35. return "http"
  36. }
  37. // Secure returns true if there is a TLS configuration.
  38. func (t *tlsInfo) Secure() bool {
  39. return t.tlsConfig != nil
  40. }