liveness

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckLiveness

func CheckLiveness(ctx context.Context, endpoints ...HasSchemeEndpoint) map[string]map[string]Result
Example
package main

import (
	"context"
	"encoding/json"
	"log"

	"github.com/xoctopus/x/misc/must"

	"github.com/xoctopus/confx/pkg/types"
	"github.com/xoctopus/confx/pkg/types/liveness"
)

func main() {
	endpoints := []liveness.HasSchemeEndpoint{
		&types.EndpointNoOption{Address: "redis://example:6379/1"},
		&types.EndpointNoOption{Address: "https://www.google.com:443"},
		&types.EndpointNoOption{Address: "mysql://example:3306/mysql"},
	}

	for _, ep := range endpoints {
		if x, ok := ep.(interface{ Init() error }); ok {
			if err := x.Init(); err != nil {
				return
			}
		}
	}

	//	{
	//		"https": {
	//			"https://www.google.com:443": {
	//				"reachable": true,
	//				"rtt(ms)": 0,
	//				"msg": "success"
	//			}
	//		},
	//		"mysql": {
	//			"mysql://example:3306/mysql": {
	//				"reachable": false,
	//				"rtt(ms)": 0,
	//				"msg": "dial tcp: lookup example: no such host"
	//			}
	//		},
	//		"redis": {
	//			"redis://example:6379/1": {
	//				"reachable": false,
	//				"rtt(ms)": 0,
	//				"msg": "dial tcp: lookup example: no such host"
	//			}
	//		}
	//	}

	m := liveness.CheckLiveness(context.Background(), endpoints...)
	log.Println("\n" + string(must.NoErrorV(json.MarshalIndent(m, "", "\t"))))

}

Types

type Checker

type Checker interface {
	LivenessCheck(ctx context.Context) Result
}

Checker check remote endpoint liveness default Endpoint already implements it using tcp dialer, components should override that

type HasSchemeEndpoint

type HasSchemeEndpoint interface {
	Scheme() string
	Endpoint() string
}

type Result

type Result interface {
	// Start starts probing endpoint liveness
	Start()
	// End ends probing with reason if failed
	End(error)
	// RTT reports rtt of liveness probing
	RTT() time.Duration
	// FailureReason denotes failure reason
	FailureReason() error
}

func NewLivenessData

func NewLivenessData() Result

NewLivenessData creates liveness Data

Jump to

Keyboard shortcuts

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