thresh

package module
v0.0.0-...-68eaa82 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2018 License: MIT Imports: 10 Imported by: 0

README

GoDoc Travis Build Status Coverage Status Go Report Card LICENSE

Table of contents

  1. About Thresh
  2. Usage
  3. Example
  4. License

About Thresh

Drawing

Library that allows you to use a healthcheck route as a checker for other routes/APIs. This was made to keep checking the size of a channel that is returned in a route, but it's open enought to serve your own porpuse.

Usage

Thresh idea is to provide inside look of what might be happening to one or more of the routes of your app or an external app. It does It by getting a list of urls that you want to parse from a environment variable named ADDRS with the following format of value: myurl1,myurl2,myurl3.

The way to implement after setting this environment variable is explicited in the following section example.

Example

This is a simple example of a implementation in a handler, you can find the full source code here.


type SomeStruct struct {
	Value int
}

func HealthCheck(c echo.Context) (err error) {
	go func() {
		addrs, err := thresh.Addrs()
		if err != nil {
			// log err somewhere
		}
		for _, ad := range addrs {
			p := new(thresh.Ping)
			p.Addr = ad
			// pass some structure
			str := new(SomeStruct)
			err = p.StartAddr(str)
			if err != nil {
				// log err somewhere
			}
			// create a checker function
			// to your structure
			CheckFields(str, p)
			// [WIP] this will warn 
			// your slack channel
			p.CheckStatus()
		}
	}()
	return c.String(http.StatusOK, "OK")
}

func CheckFields(s *SomeStruct, p *thresh.Ping) {
	if s.Value > 100 {
		p.Status = true
	}
}

License

Thresh is MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Addrs

func Addrs() (addrs []url.URL, err error)

Types

type NotifierFunc

type NotifierFunc func(addr string) error

NotifierFunc can be used to control notifications for failed status checks. Provided for static type checking.

func SlackNotifier

func SlackNotifier(token, channel string, opts ...slack.MsgOption) NotifierFunc

SlackNotifier returns a NotifierFunc for slack using the provided token. An invalid token will result in an error during CheckStatus. Channel may be either a channel name or channel ID, like token if this is invalid it will result in an error during CheckStatus.

type Ping

type Ping struct {
	Addr         url.URL
	Status       bool
	NotifierFunc NotifierFunc
}

func (*Ping) CheckStatus

func (p *Ping) CheckStatus() error

CheckStatus should be called to initiating a status check on the provided address. If the optional NotifierFunc is set this will be executed. If no NotfierFunc is set the returned error will always be nil.

func (*Ping) StartAddr

func (p *Ping) StartAddr(s interface{}) (err error)

StartAddr receives a structure and a address and unmarshals a body into it's structure

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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