Categorygithub.com/Sagleft/go-healthcheck
modulepackage
1.1.0
Repository: https://github.com/sagleft/go-healthcheck.git
Documentation: pkg.go.dev

# README

go-healthcheck

The thing to check that your service is working

           .,----,.
        .:'        `:.
      .'              `.
     .'                `.
     :                  :
     `    .'`':'`'`/    '
      `.   \  |   /   ,'
        \   \ |  /   /
         `\_..,,.._/'
          {`'-,_`'-}
          {`'-,_`'-}
          {`'-,_`'-}
           `YXXXXY'
             ~^^~

Getting started

go get github.com/Sagleft/go-healthcheck

First we create a handler on the top level of the service:

var Healthchecker *gohealth.Handler = gohealth.NewHandler(gohealth.HandlerTask{})

By default, the listening will open at: GET 127.0.0.1:8080/healthcheck. Returns the code 200 if all checks are passed, and 500 if there is an error and returns its text.

Then write checks in the necessary places in your service:

Healthchecker.AddCheckpoint(gohealth.CheckpointData{
  Name: "LastError-Checker",
  CheckCallback: func() gohealth.Signal {
    if app.LastError != nil { // example
      return gohealth.SignalError("last error: " + app.LastError.Error())
    }
    return gohealth.SignalNormal()
  },
})

Or we can put the check in a separate method:

Healthchecker.AddCheckpoint(gohealth.CheckpointData{
  Name: "LastError-Checker",
  CheckCallback: app.LastErrorCheck,
})

# Functions

NewHandler - create new health check handler for service.
SignalError - get new errorsignal.
SignalNormal - checkpoint passed.

# Structs

Checkpoint : service must pass all checkpoints before it comes to the boss battle!.
CheckpointData - health check checkpoint data.
Handler - go-healthcheck handler.
HandlerTask - healtch check handler constructor data.
Signal - service health signal.

# Type aliases

HealthCheckCallback - health check callback.