Documentation ¶
Overview ¶
Package healthz retrieves the healh of your app dependencies.
Example Usage ¶
The following is a simple example using the library:
package main import ( "fmt" "github.com/dafiti/healthz" "time" ) func main() { checkers := []healthz.Checker{ func() *healthz.Check { return &healthz.Check{ Name: "some-api", Kind: healthz.InternalService, Status: false, ResponseTime: 6 * time.Second, Optional: false, URL: "http://api.example.com", } }, } h := healthz.New("my-app", "0.0.1", checkers...) fmt.Println(h.Check()) }
Using with a HTTP Server:
package main import ( "github.com/dafiti/healthz" "net/http" "time" ) func main() { checkers := []healthz.Checker{ func() *healthz.Check { return &healthz.Check{ Name: "some-api", Kind: healthz.InternalService, Status: false, ResponseTime: 6 * time.Second, Optional: false, URL: "http://api.example.com", Details: map[string]string{ "api-key": "bf15a8f489e8f3d4bf6f77343c08ad1e", }, } }, } h := healthz.New("my-app", "0.0.1", checkers...) http.Handle("/healthz", h) http.ListenAndServe(":8080", nil) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Check ¶
type Check struct { Name string `json:"name"` Kind Kind `json:"kind"` Status bool `json:"status"` ResponseTime time.Duration `json:"response_time"` Optional bool `json:"optional"` URL string `json:"url"` Details map[string]string `json:"details"` }
Check retrieves the health of service
type Healthz ¶
Healthz defines the healthcheck configuration
type Kind ¶
type Kind uint8
Kind type
func (Kind) MarshalJSON ¶
MarshalJSON marshals Kind instance into string
type Status ¶
type Status struct { Name string `json:"name"` Version string `json:"version"` Status bool `json:"status"` Date Time `json:"date"` Checks []*Check `json:"checks"` }
Status retrieves the status of health
type Time ¶
Time it is a custom time struct for json parsing
func (*Time) MarshalJSON ¶
MarshalJSON marshals Time instance into string
func (*Time) UnmarshalJSON ¶
UnmarshalJSON unmarshals string time into Time instance
Click to show internal directories.
Click to hide internal directories.