Skip to content

Commit

Permalink
[-] improved README
Browse files Browse the repository at this point in the history
  • Loading branch information
bnkamalesh committed Jan 9, 2025
1 parent 75fde6a commit 9af24ec
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<p align="center"><img src="https://github.com/user-attachments/assets/2bd99e22-d0fa-464f-8dca-3336ec7b6e0b" alt="proberesponder gopher" width="256px"/></p>

[![](https://github.com/naughtygopher/proberesponder/actions/workflows/go.yml/badge.svg?branch=main)](https://github.com/naughtygopher/proberesponder/actions)
[![Go Reference](https://pkg.go.dev/badge/github.com/naughtygopher/proberesponder.svg)](https://pkg.go.dev/github.com/naughtygopher/proberesponder)
[![Go Report Card](https://goreportcard.com/badge/github.com/naughtygopher/proberesponder?cache_invalidate=v0.3.0)](https://goreportcard.com/report/github.com/naughtygopher/proberesponder)
Expand All @@ -8,7 +10,15 @@

Probe-responder is a package to deal with handling [appropriate statuses for Kuberentes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/). Even though the statuses are specific to Kubernetes, it can be used in any context, and can later be updated to include more if required.

# Sample usage
The sample below shows how to use proberesponder, all the statuses are "NOT OK" by default. This is intentional as the app is expected to explicitly update the respective status as OK which would be more accurate than being OK by default.

## Extras

By default a bare bones HTTP server can be setup to respond to probe request. The default HTTP handlers provided does content negotiation and provides appropriate response for JSON, HTML & plain text. For any unidentified content type, it will respond with JSON.

`AppendHealthResponse` is a helper function with which you can maintain statuses of a dependency or similar. All the custom statuses set using this and the native ones (startup, live, ready) can be fetched as a map[string]string using `HealthResponse`.

## Sample usage

```golang
package main
Expand All @@ -18,11 +28,31 @@ import (

func main() {
pRes := proberesponder.New()
// do something to startup your app & once finished
// setup an HTTP server to handle probe requests
go proberesponder.StartHTTPServer(pres, "localhost", 1234)

// with set listener you can register a callback, for when any of the statuses
// (startup, live, ready) is changed
pRes.SetListener(func(status Statuskey, value bool) {
fmt.Println(status, "changed to", value)
})

// Update the status of the app as Startup: OK
pRes.SetNotStarted(false)

// if you're running an API server (HTTP, gRPC etc.), start the servers and then setup live and ready.
// update the status of app as Live: OK
pRes.SetNotLive(false)
pRes.SetNotReady(false)
// update the status of app as Ready: OK
pRes.SetNotReady(false)

// set status of any service
pRes.AppendHealthResponse("mydb", "OK")

// retrieves all the statuses maintained by the proberesponder, it returns a map[string]string
_ = pRes.HealthResponse()
}
```

## The gopher

The gopher used here was created using [Gopherize.me](https://gopherize.me/). Just like the handyman gopher here, proberesponder helps setup, well, a probe responder!

0 comments on commit 9af24ec

Please sign in to comment.