šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

github.com/luisguillenc/httphealth

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/luisguillenc/httphealth

v0.0.0-20200210131312-e37786300489
Source
Go
Version published
Created
Source

httphealth

HTTPHealth provides a simple component that offers an http interface for health checking and monitoring using Prometheus.

Usage

package main

import (
	"errors"
	"log"
	"math/rand"
	"net"

	"github.com/sirupsen/logrus"

	"github.com/luisguillenc/httphealth"
	"github.com/luisguillenc/ipfilter"
)

func main() {
	//creates listener
	lis, err := net.Listen("tcp", "0.0.0.0:8081")
	if err != nil {
		log.Fatalf("listening: %v", err)
	}

	//constructs whitelist
	wl := ipfilter.Whitelist(
		[]string{"127.0.0.1", "192.168.1.0/24"},
	)

	//constructs logger
	logger := logrus.New()
	logger.SetLevel(logrus.DebugLevel)

	health := httphealth.New(
		&service{},
		httphealth.SetIPFilter(wl),   //sets ipfilter
		httphealth.SetLogger(logger), //sets logger
		httphealth.Metrics(true),     //enables prometheus metrics
	)
	health.Serve(lis)
}

type service struct{}

func (s service) Ping() error {
	if rand.Intn(10) > 8 {
		return errors.New("error in supervised")
	}
	return nil
}

FAQs

Package last updated on 10 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts