Skip to content

Alvarios/watcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Watcher

A simple and efficient package to handle staging and production errors.

go get github.com/Alvarios/watcher

Prerequisite

You need a Slack application that supports incoming webhooks.

Configuration

Create a SlackConfig in your go code.

package myPackage

import "github.com/Alvarios/watcher"

var Watcher watcher.SlackConfig

func main() {
    Watcher := watcher.SlackConfig{
        WebHook: "https://hooks.slack.com/services/XXXXX/XXXXX/XXXXX",
        Application: "Your application name",
    }
}

Methods

Error

Send a basic error message to Slack.

package myPackage

func MyFunction() {
	_, err := Watcher.Error("some error message")
}

Fatal

Same as Error method, but kills the running server and doesn't return any status.

package myPackage

func MyFunction() {
	Watcher.Fatal("some fatal message")
}

GinAbort

A special message formatter for Gin, that also interrupts the request.

package myPackage

import "github.com/gin-gonic/gin"

func MyMiddleware(c *gin.Context) {
	Watcher.GinAbort(c, "some error message")
}

Copyright

2020 Kushuh - MIT license