mc

package
v1.15.2 Latest Latest
Warning

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

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

Documentation

Overview

Multicurl package is a library for the multicurl tool to fetch a url from all its IPs. Some of this code is based on the fortio code. https://github.com/fortio/fortio/blob/master/fnet/network.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Days

func Days(d time.Duration) float64

Days returns the number of days in the duration (floating point).

func DumpResponseDetails

func DumpResponseDetails(w io.Writer, r *http.Response)

DumpResponseDetails sort of reconstitutes the server's response (but not really as go processes it and the raw response isn't available - use fortio curl fast client for exact bytes).

func Dur

func Dur(days float64) time.Duration

Dur returns a duration corresponding to the number of days passed.

func Filename

func Filename(cfg *Config, addr net.IP) string

func GetCA

func GetCA(caFile string) (*x509.CertPool, error)

func GetCertificate

func GetCertificate(cert, key string) ([]tls.Certificate, error)

func IPPortString

func IPPortString(ip net.IP, port int) string

func ReadIPs

func ReadIPs(filename string) ([]net.IP, error)

func Resolve

func Resolve(ctx context.Context, cfg *Config) ([]net.IP, error)

func ResolveAll

func ResolveAll(ctx context.Context, host, resolveType string) ([]net.IP, error)

func URLAddScheme

func URLAddScheme(url string) string

Types

type Config

type Config struct {
	// URL is the url to access.
	URL string
	// ResolveType is a filter for the IPs to use, `ip4`, `ip6`, or `ip` for both.
	ResolveType string
	// Method is the HTTP method to use, defaults to GET. (do use POST/PUT/... if passing a Payload)
	Method string
	// RequestTimeout is the timeout for a single request to succeed by.
	// Pass `context.WithTimeout(context.Background(), totalTimeout)` as context to MultiCurl() for a total timeout.
	RequestTimeout time.Duration
	// IncludeHeaders if true will include the response headers in the output.
	IncludeHeaders bool
	// Headers are the headers to use for the request. Must be initialized. Or call NewConfig().
	Headers http.Header
	// HostOverride is the host/authority to use for the request. If empty, the host from the URL is used.
	// This will also change the ServerName used for TLS handshake (sni) so in essence passing HostOverride
	// is the same as passing the IPs of the server of the url and using the name from HostOverride as the url.
	HostOverride string
	// OutputPattern is the pattern to use for the output file names, must contain a % which will get replaced by
	// the IP of the target. If empty or "-", output is written to stdout. If "none" no output is written.
	OutputPattern string
	// Payload to send or nil if none.
	Payload []byte
	// Source file of the IPs to use instead of resolving the host IPs. Use "-" to read from stdin.
	IPFile string
	// Expected http result code: other codes will count as errors. 0 (default) treats non 200 as warnings.
	ExpectedCode int
	// Repeat until no errors. 0 (default) means no repeat. -1 means repeat until no errors (context timeout still applies.
	// a positive number means repeat that at most that many times.
	MaxRepeat int
	// Delay between repeats. NewConfig will set this to 5 seconds as initial value.
	RepeatDelay time.Duration
	// Limit the number of IPs to use. 0 (default) means no limit.
	MaxIPs int
	// Re-Lookup between iterations. False by default. doesn't apply if IPFile is set.
	ReLookup bool
	// Cert expiration error threshold (if a cert is found expiring sooner than this).
	CertExpiryError time.Duration
	// Path of an alternate CA file to use for TLS validation (instead of system).
	CAFile string
	// Insecure will continue despite certificate validation errors.
	Insecure bool
	// Client certificate file path to provide to server for mutual TLS.
	Cert string
	// Client certificate key file path to provide to server for mutual TLS.
	Key string
	// contains filtered or unexported fields
}

Config object for MultiCurl to avoid passing too many parameters.

func NewConfig

func NewConfig() *Config

func (*Config) AddAndValidateExtraHeader

func (cfg *Config) AddAndValidateExtraHeader(hdr string) error

AddAndValidateExtraHeader collects extra headers (see cli/main.go for example). Inspired/borrowed from fortio/fhttp.

type ResultStats

type ResultStats struct {
	// Number of errors (if any request is made at all)
	Errors int
	// Number of warnings, ie non 200 responses
	Warnings int
	// Addresses queried (keys of Codes and Sizes)
	Addresses []string
	// http result code for that address (maps to Warnings)
	Codes map[string]int
	// Size of the response from that address
	Sizes map[string]int
	// Iterations done
	Iterations int
	// Shortest certificate expiration found
	ShortestCertExpiry *time.Time `json:"ShortestCertExpiry,omitempty"`
}

ResultStats is the details of the MultCurl run when any request is made at all.

func MultiCurl

func MultiCurl(ctx context.Context, cfg *Config) (int, ResultStats)

MultiCurl is the main function of the multicurl tool. timeout is per request/ip. Returns 0 if all is successful, the number of errors otherwise. ResultStats is the details of the run (see ResultStats).

Jump to

Keyboard shortcuts

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