probe

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBPinger

type DBPinger interface {
	PingContext(ctx context.Context) error
}

DBPinger captures the subset of *sql.DB used for readiness checks.

type Func

type Func func(ctx context.Context) error

Func represents a health check that returns an error when the resource is unavailable.

func NewDBPingProbe

func NewDBPingProbe(name string, db DBPinger) Func

NewDBPingProbe creates a Func that pings databases such as PostgreSQL using the provided client.

func NewHTTPProbe

func NewHTTPProbe(name, method, target string, client HTTPDoer) Func

NewHTTPProbe creates a Func that performs an HTTP request against the supplied endpoint. The probe succeeds when the response status code is within the 2xx range.

func NewMongoPingProbe

func NewMongoPingProbe(client MongoPinger, readPref *readpref.ReadPref) Func

NewMongoPingProbe creates a Func that pings MongoDB using the provided client. If readPref is nil it defaults to readpref.Primary.

func NewPingProbe

func NewPingProbe(name string, fn PingFunc) Func

NewPingProbe wraps a PingFunc with standardised error handling suitable for InfoHandler probes.

Example
package main

import (
	"context"
	"fmt"

	"github.com/drblury/apiweaver/probe"
)

func main() {
	probeFunc := probe.NewPingProbe("noop", func(ctx context.Context) error {
		return nil
	})
	fmt.Println(probeFunc(context.Background()))
}
Output:

<nil>

type HTTPDoer

type HTTPDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPDoer represents the subset of *http.Client required by the HTTP probe helper.

type MongoPinger

type MongoPinger interface {
	Ping(ctx context.Context, rp *readpref.ReadPref) error
}

MongoPinger captures the subset of the MongoDB client used for readiness checks.

type PingFunc

type PingFunc func(ctx context.Context) error

PingFunc represents a health check that returns an error when the resource is unavailable.

Jump to

Keyboard shortcuts

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