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: 17 modules, 16 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址