Go healthcheck for your apps
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
checker
.gitignore
.travis.yml
CONTRIBUTING.md
Gopkg.lock
Gopkg.toml
LICENSE
Makefile
README.md
doc.go
docker-compose.yml
health.go
health_test.go

README.md

Htz

Build Status Codecov branch GoDoc Go Report Card License

Go healthcheck for your apps

Instalation

Htz requires Go 1.10 or later.

go get github.com/fabiorphp/htz

If you want to get an specific version, please use the example below:

go get gopkg.in/fabiorphp/htz.v0

Usage

Simple usage

package main

import (
	"encoding/json"
	"fmt"
	"github.com/fabiorphp/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))
}

HTTP Check

package main

import (
	"github.com/fabiorphp/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)
}

Available checkers

DB

package main

import (
	"database/sql"
	"encoding/json"
	"fmt"
	"github.com/fabiorphp/htz"
	"github.com/fabiorphp/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))
}

Redis

package main

import (
	"encoding/json"
	"fmt"
	"github.com/fabiorphp/htz"
	"github.com/fabiorphp/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))
}

Runtime

package main

import (
	"fmt"
	"github.com/fabiorphp/htz"
	"github.com/fabiorphp/htz/checker"
)

func main() {
	h := htz.New("my-app", "0.0.1", checker.Runtime(false))
	res, _ := json.MarshalIndent(h.Check(), "", "  ")

	fmt.Println(string(res))
}

Development

Requirements

Makefile

// 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

License

This project is released under the MIT licence. See LICENSE for more details.