项目作者: faabiosr

项目描述 :
Go healthcheck for your apps
高级语言: Go
项目地址: git://github.com/faabiosr/htz.git
创建时间: 2018-07-31T14:36:59Z
项目社区:https://github.com/faabiosr/htz

开源协议:MIT License

下载


Htz

Build Status
Codecov branch
GoDoc
Go Report Card
License

Go healthcheck for your apps

Instalation

Htz requires Go 1.10 or later.

  1. go get github.com/faabiosr/htz

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

  1. go get gopkg.in/faabiosr/htz.v0

Usage

Simple usage

  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/faabiosr/htz"
  6. "time"
  7. )
  8. func main() {
  9. checkers := []htz.Checker{
  10. func() *htz.Check {
  11. return &htz.Check{
  12. Name: "some-api",
  13. Type: "internal-service",
  14. Status: false,
  15. ResponseTime: 6 * time.Second,
  16. Optional: false,
  17. Details: map[string]interface{}{
  18. "url": "internal-service.api",
  19. },
  20. }
  21. },
  22. }
  23. h := htz.New("my-app", "0.0.1", checkers...)
  24. res, _ := json.MarshalIndent(h.Check(), "", " ")
  25. fmt.Println(string(res))
  26. }

HTTP Check

  1. package main
  2. import (
  3. "github.com/faabiosr/htz"
  4. "net/http"
  5. "time"
  6. )
  7. func main() {
  8. checkers := []htz.Checker{
  9. func() *htz.Check {
  10. return &htz.Check{
  11. Name: "some-api",
  12. Type: "internal-service",
  13. Status: false,
  14. ResponseTime: 6 * time.Second,
  15. Optional: false,
  16. Details: map[string]interface{}{
  17. "url": "internal-service.api",
  18. },
  19. }
  20. },
  21. }
  22. h := htz.New("my-app", "0.0.1", checkers...)
  23. http.Handle("/htz", h)
  24. http.ListenAndServe(":8080", nil)
  25. }

Available checkers

DB

  1. package main
  2. import (
  3. "database/sql"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/faabiosr/htz"
  7. "github.com/faabiosr/htz/checker"
  8. _"github.com/lib/pq"
  9. )
  10. func main() {
  11. db, _ := sql.Open("postgres", "user=htz dbname=htz")
  12. h := htz.New("my-app", "0.0.1", checker.DB(db, true))
  13. res, _ := json.MarshalIndent(h.Check(), "", " ")
  14. fmt.Println(string(res))
  15. }

Redis

  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/faabiosr/htz"
  6. "github.com/faabiosr/htz/checker"
  7. "github.com/go-redis/redis"
  8. )
  9. func main() {
  10. client := redis.NewClient(&redis.Options{
  11. Addr: "localhost:6379",
  12. })
  13. h := htz.New("my-app", "0.0.1", checker.Redis(client, true))
  14. res, _ := json.MarshalIndent(h.Check(), "", " ")
  15. fmt.Println(string(res))
  16. }

Runtime

  1. package main
  2. import (
  3. "fmt"
  4. "github.com/faabiosr/htz"
  5. "github.com/faabiosr/htz/checker"
  6. )
  7. func main() {
  8. h := htz.New("my-app", "0.0.1", checker.Runtime(false))
  9. res, _ := json.MarshalIndent(h.Check(), "", " ")
  10. fmt.Println(string(res))
  11. }

Development

Requirements

Makefile

  1. // Clean up
  2. $ make clean
  3. // Creates folders and download dependencies
  4. $ make configure
  5. // Run tests and generates html coverage file
  6. make cover
  7. // Download project dependencies
  8. make depend
  9. // Format all go files
  10. make fmt
  11. // Run linters
  12. make lint
  13. // Run tests
  14. make test

License

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