healthcheck

package module
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: MIT Imports: 7 Imported by: 0

README

healthcheck - A Go package for healthcheck

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release

Installation

To install the package, run:

go get github.com/go-zoox/healthcheck

Getting Started

package main

import (
	"context"

	"github.com/go-zoox/healthcheck"
)

func main() {
	// HTTP
	ok, err := healthcheck.HTTP("https://github.com")
	if err != nil {
		panic(err)
	}
	fmt.Println("HTTP => https://github.com", ok)

	// TCP
	ok, err = healthcheck.TCP("127.0.0.1", 443)
	if err != nil {
		panic(err)
	}
	fmt.Println("TCP => 127.0.0.1:443", ok)

	// Ping
	ok, err = healthcheck.Ping("github.com")
	if err != nil {
		panic(err)
	}
	fmt.Println("Ping => github.com", ok)

	// Keyword in HTTP response
	ok, err = healthcheck.Keyword("https://github.com", "GitHub")
	if err != nil {
		panic(err)
	}
	fmt.Println("Keyword => https://github.com", ok)
}

License

GoZoox is released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "1.3.2"

Version is the current version of the i18n package.

Functions

func HTTP

func HTTP(url string, opts ...*HTTPOptions) (ok bool, err error)

HTTP checks if the given url is healthy (reachable) via HTTP

func Keyword

func Keyword(url, keyword string, opts ...*KeywordOptions) (bool, error)

Keyword checks if the given url is healthy (reachable) via HTTP and contains the given keyword

func Ping

func Ping(domain string, timeout ...time.Duration) (ok bool, err error)

Ping checks if a domain is reachable.

func TCP

func TCP(ip string, port int, timeout ...time.Duration) (ok bool, err error)

TCP checks if the given ip and port is healthy (reachable) via TCP

func UDP added in v1.0.5

func UDP(ip string, port int, timeout ...time.Duration) (ok bool, err error)

UDP checks if the given ip and port is healthy (reachable) via UDP

Types

type HTTPOptions

type HTTPOptions struct {
	Timeout time.Duration
	//
	Method string
	Header map[string]string
	Query  map[string]string
	Body   any
	//
	OkStatusCodes []int
	//
	Ok func(response *fetch.Response) bool
}

HTTPOptions is the options for the HTTP health check

type HealthCheck added in v1.2.0

type HealthCheck interface {
	// HTTP checks if the given url is healthy (reachable) via HTTP
	HTTP(url string, opts ...*HTTPOptions) (ok bool, err error)

	// TCP checks if the given ip and port is healthy (reachable) via TCP
	TCP(ip string, port int, timeout ...time.Duration) (ok bool, err error)

	// UDP checks if the given ip and port is healthy (reachable) via UDP
	UDP(ip string, port int, timeout ...time.Duration) (ok bool, err error)

	// Ping checks if the given domain is healthy (reachable) via ICMP
	Ping(domain string, timeout ...time.Duration) (ok bool, err error)

	// Keyword checks if the given url is healthy (reachable) via HTTP and contains the given keyword
	Keyword(url, keyword string, opts ...*KeywordOptions) (bool, error)
}

HealthCheck is the interface for health check

func New added in v1.2.0

func New() HealthCheck

New returns a new HealthCheck

type KeywordOptions

type KeywordOptions struct {
	HTTPOptions
}

KeywordOptions is the options for keyword health check

Jump to

Keyboard shortcuts

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