github.com/ethereum/go-ethereum@v1.16.1/metrics/healthcheck.go (about)

     1  package metrics
     2  
     3  // NewHealthcheck constructs a new Healthcheck which will use the given
     4  // function to update its status.
     5  func NewHealthcheck(f func(*Healthcheck)) *Healthcheck {
     6  	return &Healthcheck{nil, f}
     7  }
     8  
     9  // Healthcheck is the standard implementation of a Healthcheck and
    10  // stores the status and a function to call to update the status.
    11  type Healthcheck struct {
    12  	err error
    13  	f   func(*Healthcheck)
    14  }
    15  
    16  // Check runs the healthcheck function to update the healthcheck's status.
    17  func (h *Healthcheck) Check() {
    18  	h.f(h)
    19  }
    20  
    21  // Error returns the healthcheck's status, which will be nil if it is healthy.
    22  func (h *Healthcheck) Error() error {
    23  	return h.err
    24  }
    25  
    26  // Healthy marks the healthcheck as healthy.
    27  func (h *Healthcheck) Healthy() {
    28  	h.err = nil
    29  }
    30  
    31  // Unhealthy marks the healthcheck as unhealthy.  The error is stored and
    32  // may be retrieved by the Error method.
    33  func (h *Healthcheck) Unhealthy(err error) {
    34  	h.err = err
    35  }