Version: v0.1.4 Latest Latest

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

Go to latest
Published: Aug 9, 2019 License: Apache-2.0 Imports: 14 Imported by: 4




This section is empty.


This section is empty.


func GetMyIp

func GetMyIp() string

GetMyIp returns your primary local IP address (as from `ifconfig`). Note that a docker container has a different primary local IP address (172.something) than your base host.

func HostNoPort

func HostNoPort(addr string) string

func LocationFromEnv

func LocationFromEnv() string

LocationFromEnv returns the current location from environment variables: REP_LOCATION, if defined; otherwise REP_CITY "," REP_COUNTRY, if defined; otherwise "" (empty string)

func LocationOrIp

func LocationOrIp(loc *string) string

LocationOrIp returns the loc string, if it has a value, or else the IP address as determined by GetMyIp().

func Msec

func Msec(d time.Duration) float64

Msec converts a time.Duration to a floating point number of seconds.

func ParseURL

func ParseURL(uri string) *url.URL

Parse the uri argument and return URL object for it, or nil on failure.

func PingTimesHeader

func PingTimesHeader() string

PingTimesHeader returns a column header string with field names corresponding to the values onto the PingTimes structure, in the same order as the string returned by MsecTsv().

func SafeStrPtr

func SafeStrPtr(sp *string, ifnil string) string

I don't know why golang string doesn't already have this feature.

func TextHeader

func TextHeader(file *os.File)

TextHeader dumps a column header corresponding to the values onto the file handle provided. (Included for backwards compatibility.)


type PingTimes

type PingTimes struct {
	Start    time.Time     // time we started the ping
	DnsLk    time.Duration // DNS Lookup
	TcpHs    time.Duration // TCP Handshake
	TlsHs    time.Duration // TLS Handshake
	Reply    time.Duration // HTTP Reply (first byte)
	Close    time.Duration // HTTP Reply (last byte / closed)
	Total    time.Duration // (Calculated) Total response time (see RespTime() below)
	DestUrl  *string       // URL that received the request
	Location *string       // Client location, City,Country
	Remote   string        // Server IP from DNS resolution
	RespCode int           // HTTP response code or -1 (for network failure)
	Size     int64         // total response bytes

PingTimes holds the components of an HTTP ping request for reporting performance (to cloudwatch, or whatever). See the receiver methods below.

func FetchURL

func FetchURL(rawurl string, myLocation string) *PingTimes

FetchURL makes an HTTP request to the given URL, reads and discards the response body, and returns a PingTimes object with detailed timing information from the fetch. The caller should pass in a valid location string, for example "City,Country" where the client is running.

func (*PingTimes) DumpJson

func (pt *PingTimes) DumpJson(file *os.File) error

DumpJson writes ping times as JSON using native (nanosecond) timestamp values into the given open file.

func (*PingTimes) DumpText

func (pt *PingTimes) DumpText(file *os.File)

DumpText writes ping times as tab-separated milliseconds into the file.

func (*PingTimes) MsecTsv

func (pt *PingTimes) MsecTsv() string

MsecTsv returns a tab separated values string with the (Unix epoch) timestamp of the start of the test followed by the msec time deltas for each of the time component fields as msec.uuu (three digits of microseconds), and then the other values of PingTimes.

func (*PingTimes) RespTime

func (pt *PingTimes) RespTime() time.Duration

RespTime returns the total duration from the TCP open until the TCP close. DNS lookup time is NOT included in this measure. The time.Duration returned will be zero iff the request failed. This method sets or changes the pt.Total value.

func (*PingTimes) String

func (pt *PingTimes) String() string

String returns a canonical string representation of the PingTimes argument using golang native representatino of time.Duration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL