Go healthcheck for your apps
Go healthcheck for your apps
Htz requires Go 1.10 or later.
go get github.com/faabiosr/htz
If you want to get an specific version, please use the example below:
go get gopkg.in/faabiosr/htz.v0
package main
import (
"encoding/json"
"fmt"
"github.com/faabiosr/htz"
"time"
)
func main() {
checkers := []htz.Checker{
func() *htz.Check {
return &htz.Check{
Name: "some-api",
Type: "internal-service",
Status: false,
ResponseTime: 6 * time.Second,
Optional: false,
Details: map[string]interface{}{
"url": "internal-service.api",
},
}
},
}
h := htz.New("my-app", "0.0.1", checkers...)
res, _ := json.MarshalIndent(h.Check(), "", " ")
fmt.Println(string(res))
}
package main
import (
"github.com/faabiosr/htz"
"net/http"
"time"
)
func main() {
checkers := []htz.Checker{
func() *htz.Check {
return &htz.Check{
Name: "some-api",
Type: "internal-service",
Status: false,
ResponseTime: 6 * time.Second,
Optional: false,
Details: map[string]interface{}{
"url": "internal-service.api",
},
}
},
}
h := htz.New("my-app", "0.0.1", checkers...)
http.Handle("/htz", h)
http.ListenAndServe(":8080", nil)
}
package main
import (
"database/sql"
"encoding/json"
"fmt"
"github.com/faabiosr/htz"
"github.com/faabiosr/htz/checker"
_"github.com/lib/pq"
)
func main() {
db, _ := sql.Open("postgres", "user=htz dbname=htz")
h := htz.New("my-app", "0.0.1", checker.DB(db, true))
res, _ := json.MarshalIndent(h.Check(), "", " ")
fmt.Println(string(res))
}
package main
import (
"encoding/json"
"fmt"
"github.com/faabiosr/htz"
"github.com/faabiosr/htz/checker"
"github.com/go-redis/redis"
)
func main() {
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
})
h := htz.New("my-app", "0.0.1", checker.Redis(client, true))
res, _ := json.MarshalIndent(h.Check(), "", " ")
fmt.Println(string(res))
}
package main
import (
"fmt"
"github.com/faabiosr/htz"
"github.com/faabiosr/htz/checker"
)
func main() {
h := htz.New("my-app", "0.0.1", checker.Runtime(false))
res, _ := json.MarshalIndent(h.Check(), "", " ")
fmt.Println(string(res))
}
// Clean up
$ make clean
// Creates folders and download dependencies
$ make configure
// Run tests and generates html coverage file
make cover
// Download project dependencies
make depend
// Format all go files
make fmt
// Run linters
make lint
// Run tests
make test
This project is released under the MIT licence. See LICENSE for more details.