Skip to content

Latest commit

 

History

History
69 lines (55 loc) · 1.54 KB

README.md

File metadata and controls

69 lines (55 loc) · 1.54 KB

gin-health-check

Build Status CodeCov GoDoc License

A health check middleware for Gin.

Installation

$ go get -u github.com/RaMin0/gin-health-check

Usage

Default Config

import (
	healthcheck "github.com/RaMin0/gin-health-check"
	"github.com/gin-gonic/gin"
)

func main() {
	router := gin.Default()
	router.Use(healthcheck.Default())
}
$ curl -iL -XGET -H "X-Health-Check: 1" http://localhost
  # HTTP/1.1 200 OK
  # Content-Length: 2
  # Content-Type: text/plain; charset=utf-8
  #
  # ok

Custom Config

import (
	"net/http"

	healthcheck "github.com/RaMin0/gin-health-check"
	"github.com/gin-gonic/gin"
)

func main() {
	router := gin.Default()
	router.Use(healthcheck.New(healthcheck.Config{
		HeaderName:   "X-Custom-Header",
		HeaderValue:  "customValue",
		ResponseCode: http.StatusTeapot,
		ResponseText: "teapot",
	}))
}
$ curl -iL -XGET -H "X-Custom-Header: customValue" http://localhost
  # HTTP/1.1 418 I'm a teapot
  # Content-Length: 6
  # Content-Type: text/plain; charset=utf-8
  #
  # teapot