ping

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ping sends pings to a heartbeat monitor through the Ping API, a POST to the monitor's ping URL or to /start, /fail or /<exit-code> after it. The token in the URL is the only credential, so messages show the URL through Masked or MaskURL.

Index

Constants

View Source
const (
	// BodyMaxBytes is how much of a ping's body the Ping API keeps.
	BodyMaxBytes   = 10 * 1024
	DefaultTimeout = 30 * time.Second
)

Variables

View Source
var (
	// ErrNotPingURL means the URL is not the origin followed by a token, such
	// as one copied with /start on the end.
	ErrNotPingURL = errors.New("not a ping URL")
	// ErrInsecure means plain http to a host other than this machine.
	ErrInsecure = errors.New("ping URL must use https")
	// ErrMaskedToken means the URL ends in a mask instead of the token, either
	// the API's **** for a key without monitors:write or the CLI's own.
	ErrMaskedToken = errors.New("ping URL token is masked")
)

Functions

func FormatSize

func FormatSize(n int64) string

FormatSize writes a byte count for people: 102 bytes, 10 KB, 37.1 KB.

func IsNotFound

func IsNotFound(err error) bool

func MaskURL

func MaskURL(raw string) string

MaskURL hides every path segment of raw except masks and the Ping API's own suffixes, so a message about a URL ParseURL rejected never shows a token.

Types

type Client

type Client struct {
	// HTTPClient sends the pings. Its redirect policy is ignored, since a
	// redirect could carry the body to another host.
	HTTPClient *http.Client
	UserAgent  string
	// Timeout bounds one ping, retries included. Zero is DefaultTimeout.
	Timeout time.Duration
	// contains filtered or unexported fields
}

func (*Client) ExitCode

func (c *Client) ExitCode(ctx context.Context, u *URL, code int, body []byte) error

ExitCode sends code, which must be 0 to 255, with body as the ping's body.

func (*Client) Fail

func (c *Client) Fail(ctx context.Context, u *URL, body []byte) error

func (*Client) Start

func (c *Client) Start(ctx context.Context, u *URL) error

type SendError

type SendError struct {
	// Status is the last answer's status, or 0 when none came.
	Status int
	// Err is the last network error when no answer came. Nil means time
	// ran out while waiting for one.
	Err     error
	Timeout time.Duration
}

SendError is a ping that got no 2xx answer within its timeout.

func (*SendError) Error

func (e *SendError) Error() string

func (*SendError) Unwrap

func (e *SendError) Unwrap() error

type Tail

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

Tail keeps the last bytes written to it. It is safe for concurrent writes, such as a command's stdout and stderr.

func NewTail

func NewTail(max int) *Tail

func (*Tail) Bytes

func (t *Tail) Bytes() []byte

Bytes returns everything written when it fits. Otherwise it returns a marker line saying how much was dropped, then the last bytes from the start of a line, together at most max bytes.

func (*Tail) Write

func (t *Tail) Write(p []byte) (int, error)

func (*Tail) Written

func (t *Tail) Written() int64

Written is how many bytes were written, kept or not.

type URL

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

URL is a checked ping URL.

func ParseURL

func ParseURL(raw string) (*URL, error)

ParseURL accepts https://<host>/<token>, or plain http for localhost. Any other path, a query or a fragment is rejected rather than pinged.

func (*URL) Masked

func (u *URL) Masked() string

Masked is the URL with its token hidden.

Jump to

Keyboard shortcuts

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