healthcheck

package module
v0.0.0-...-a677317 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2018 License: MIT Imports: 2 Imported by: 11

README

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultHeaderName default header name
	DefaultHeaderName = "X-Health-Check"

	// DefaultHeaderValue default header value
	DefaultHeaderValue = "1"

	// DefaultResponseCode default response code
	DefaultResponseCode = http.StatusOK

	// DefaultResponseText default response text
	DefaultResponseText = "ok"

	// DefaultConfig default config
	DefaultConfig = Config{
		HeaderName:   DefaultHeaderName,
		HeaderValue:  DefaultHeaderValue,
		ResponseCode: DefaultResponseCode,
		ResponseText: DefaultResponseText}
)

Functions

func Default

func Default() gin.HandlerFunc

Default creates a new middileware with the default configuration

func New

func New(cfg Config) gin.HandlerFunc

New creates a new middileware with the `cfg`

Types

type Config

type Config struct {
	HeaderName   string
	HeaderValue  string
	ResponseCode int
	ResponseText string
}

Config holds the configuration values

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL