healthclient

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2024 License: BSD-3-Clause Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ErrInvalidBaseURL errors.Msg = "invalid bound base url"
	ErrRequestFailed  errors.Msg = "request failed"
)
View Source
const ErrUnknownTransportType errors.Msg = "cannot add tls.Config to http.Client.Transport of unknown type"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a simple http.Client which can be used to perform health checks on a target (web)service.

func New

func New(conf Config, opts ...Option) (*Client, error)

func (*Client) Request

func (c *Client) Request(ctx context.Context) (healthcheck.Status, error)

func (*Client) TLSConfig

func (c *Client) TLSConfig() *tls.Config

func (*Client) TargetURL

func (c *Client) TargetURL() (*urlpkg.URL, error)

func (*Client) With

func (c *Client) With(opts ...Option) error

type Config

type Config struct {
	// TargetHostname is the hostname or ip address of the target server.
	TargetHostname string `env:"" default:"localhost"`
	// TargetPort is the port of the target server.
	TargetPort uint16 `env:"" default:"8080"`
	// TargetPath is the path to the health check endpoint on the target server.
	TargetPath string `env:"" default:"/healthy"`
	// RequestTimeout is the maximum time to wait for a health check response.
	RequestTimeout time.Duration `env:"" default:"3s"`
}

func DefaultConfig

func DefaultConfig() Config

type InvalidStatusCode

type InvalidStatusCode struct {
	Code int
}

InvalidStatusCode contains the non-expected status code received from a health check request.

func (InvalidStatusCode) Error

func (e InvalidStatusCode) Error() string

type Option

type Option func(c *Client) error

func WithBindTargetBaseURL

func WithBindTargetBaseURL(ptr *string) Option

WithBindTargetBaseURL where ptr points to a strings which contains the base url to the target server, of form "[scheme://]ipaddr|hostname[:port]", without trailing slash.

func WithBindTargetPath

func WithBindTargetPath(ptr *string) Option

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient allows to set a custom internal http.Client to the Client.

func WithTLSConfig

func WithTLSConfig(conf *tls.Config, opts ...easytls.Option) Option

WithTLSConfig sets the provided tls.Config to the Client's internal http.Transport.TLSClientConfig. Any provided easytls.Option(s) will be applied to this tls.Config using easytls.Apply.

Jump to

Keyboard shortcuts

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