http

package
v1.33.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckFileExists

func CheckFileExists(filename string) error

func GetTLSConfig

func GetTLSConfig(s *ClientTLSSettings) (*tls.Config, error)

func GetX509KeyPair

func GetX509KeyPair(certFile, keyFile, keyPassword string) (tls.Certificate, error)

func NewRoundTripper added in v1.16.1

func NewRoundTripper(ctx context.Context, log *zap.SugaredLogger, s ClientSettings, identity token.Identity) (http.RoundTripper, error)

Types

type BackstopError

type BackstopError struct {
	ErrorID string `json:"error_id"`
	Errors  Errors `json:"errors"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ctx context.Context, log *zap.SugaredLogger, svc ClientSettings, identity token.Identity) (*Client, error)

func (*Client) GetClient

func (s *Client) GetClient() *http.Client

func (*Client) NewRequest

func (s *Client) NewRequest(method, relativeUrl string, body io.Reader) (*http.Request, error)

type ClientAuthType

type ClientAuthType string
const (
	ClientAuthNone    ClientAuthType = "none"
	ClientAuthWant    ClientAuthType = "want"
	ClientAuthNeed    ClientAuthType = "need"
	ClientAuthAny     ClientAuthType = "any"
	ClientAuthRequest ClientAuthType = "request"
)

type ClientSettings

type ClientSettings struct {
	// Client base URL (e.g. https://my-service/some/path/)
	BaseUrl string `yaml:"baseUrl,omitempty" json:"baseUrl,omitempty"`
	// MaxIdleConns controls the maximum number of idle (keep-alive)
	// connections for the given service. Zero means no limit.
	// From http.Transport
	// Defaults to 10
	MaxIdleConns int `yaml:"maxIdleConns,omitempty" json:"maxIdleConns,omitempty"`
	// IdleConnTimeoutSeconds is the maximum amount of time an idle
	// (keep-alive) connection will remain idle before closing
	// itself.
	// Zero means no limit.
	// From http.Transport
	// Defaults to 90s
	IdleConnTimeoutSeconds int32 `yaml:"idleConnTimeoutSeconds,omitempty" json:"idleConnTimeoutSeconds,omitempty"`
	// MaxConnections optionally limits the number of connections to the service.
	// Zero means no limit.
	// Defaults to zero
	MaxConnections int32 `yaml:"maxConnections,omitempty" json:"maxConnections,omitempty"`
	// TLSHandshakeTimeoutSeconds specifies the maximum amount of time waiting to
	// wait for a TLS handshake. Zero means no timeout.
	// From http.Transport
	// Defaults to 10s
	TLSHandshakeTimeoutSeconds int32 `yaml:"tlsHandshakeTimeoutSeconds,omitempty" json:"tlsHandshakeTimeoutSeconds,omitempty"`

	// TimeoutSeconds limits how long we wait for a response
	// Zero means no limit
	// Defaults to 30s
	TimeoutSeconds int32 `yaml:"timeoutSeconds,omitempty" json:"timeoutSeconds,omitempty"`

	// KeepAliveSeconds specifies the interval between keep-alive
	// probes for an active network connection.
	// If zero, keep-alive probes are sent with a default value
	// (currently 15 seconds), if supported by the protocol and operating
	// system. Network protocols or operating systems that do
	// not support keep-alives ignore this field.
	// If negative, keep-alive probes are disabled.
	// ^ from net.dial
	// Defaults to 30s
	KeepAliveSeconds int32 `yaml:"keepAliveSeconds,omitempty" json:"keepAliveSeconds,omitempty"`

	TLS *ClientTLSSettings `yaml:"tls,omitempty" json:"tls,omitempty"`
}

func NewDefaultClientSettings

func NewDefaultClientSettings() ClientSettings

type ClientTLSSettings

type ClientTLSSettings struct {
	// Override server name to check on certificate
	ServerName string `yaml:"serverName,omitempty" json:"serverName,omitempty"`
	// Don't check server name
	InsecureSkipVerify bool `yaml:"insecureSkipVerify" json:"insecureSkipVerify"`
	// Key file if the cert file doesn't provide it
	ClientKeyFile string `yaml:"clientKeyFile,omitempty" json:"clientKeyFile,omitempty"`
	// Key password if the key is encrypted
	ClientKeyPassword string `yaml:"clientKeyFilePassword,omitempty" json:"clientKeyFilePassword,omitempty"`
	// If not provided, it will default to the system cacerts
	CAcertFile string `yaml:"cacertFile,omitempty" json:"cacertFile,omitempty"`
	// Client certificate file - useful for mTLS
	ClientCertFile string `yaml:"clientCertFile,omitempty" json:"clientCertFile,omitempty"`
}

type Configuration added in v1.7.1

type Configuration struct {
	HTTP HTTP
}

func (Configuration) GetAddr added in v1.7.1

func (s Configuration) GetAddr() string

type Errors

type Errors []struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

type HTTP

type HTTP struct {
	Prefix string
	Host   string
	Port   uint32
	SSL    SSL
}

type SSL

type SSL struct {
	// Enable SSL
	Enabled bool
	// Certificate file, can be just a PEM of cert + key or just the cert in which case you'll also need
	// to provide the key file
	CertFile string
	// Key file if the cert file doesn't provide it
	KeyFile string
	// Key password if the key is encrypted
	KeyPassword string
	// when using mTLS, CA PEM. If not provided, it will default to the certificate of the server as a CA
	CAcertFile string
	// Client auth requested (none, want, need, any, request)
	ClientAuth ClientAuthType
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(config Configuration) *Server

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

func (*Server) Start

func (s *Server) Start(router http.Handler) error

Start starts the server on the configured port

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL