https://github.com/arxdsilva/thresh
[LIB] Check multiple endpoints states and get notified
https://github.com/arxdsilva/thresh
alert go golang healthcheck json library
Last synced: 3 months ago
JSON representation
[LIB] Check multiple endpoints states and get notified
- Host: GitHub
- URL: https://github.com/arxdsilva/thresh
- Owner: arxdsilva
- License: mit
- Created: 2018-03-13T12:41:14.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-10-03T01:49:03.000Z (over 7 years ago)
- Last Synced: 2025-01-08T18:34:26.507Z (over 1 year ago)
- Topics: alert, go, golang, healthcheck, json, library
- Language: Go
- Homepage:
- Size: 964 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://godoc.org/github.com/arxdsilva/thresh)
[](https://travis-ci.org/arxdsilva/thresh)
[](https://coveralls.io/github/arxdsilva/thresh?branch=master)
[](https://goreportcard.com/report/github.com/arxdsilva/thresh)
[](LICENSE)
# Table of contents
1. [About Thresh](https://github.com/arxdsilva/thresh#about-thresh)
2. [Usage](https://github.com/arxdsilva/thresh#usage)
3. [Example](https://github.com/arxdsilva/thresh#example)
4. [License](https://github.com/arxdsilva/thresh#license)
# About Thresh

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](https://github.com/arxdsilva/thresh#example).
# [Example](https://github.com/arxdsilva/thresh/tree/master/example)
This is a simple example of a implementation in a handler, you can find the full source code [here](https://github.com/arxdsilva/thresh/tree/master/_example).
```golang
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](https://github.com/arxdsilva/thresh/blob/master/LICENSE).