# README
Hawk catcher for Golang
Golang errors catcher for Hawk.so
Installation
Go Get
go get https://github.com/codex-team/hawk.go
Usage
Initiate Hawk catcher
options := hawk.DefaultHawkOptions()
options.AccessToken = "<TOKEN>"
options.Domain = "stage-k1.hawk.so"
options.Debug = true
options.Transport = hawk.HTTPTransport{}
options.AffectedUser = hawk.AffectedUser{Id: "01", Name: "default user"}
catcher, err := hawk.New(options)
if err != nil {
log.Fatal(err)
}
Run Hawk errors collection and panic recovery
go catcher.Run()
defer catcher.Stop()
You can manually send errors and context information
err = catcher.Catch(fmt.Errorf("manual exception with context"),
hawk.WithContext(struct{ Timestamp string }{Timestamp: strconv.Itoa(int(time.Now().Unix()))}),
hawk.WithUser(hawk.AffectedUser{Id: "uid", Name: "N0str"}),
hawk.WithRelease("v-3.7"),
)
Full code example
package main
import (
"fmt"
"log"
"os"
"os/signal"
"strconv"
"syscall"
"time"
"github.com/codex-team/hawk.go"
)
func main() {
options := hawk.DefaultHawkOptions()
options.AccessToken = "<TOKEN>"
options.Domain = "stage-k1.hawk.so"
options.Debug = true
options.Transport = hawk.HTTPTransport{}
options.AffectedUser = hawk.AffectedUser{Id: "01", Name: "default user"}
catcher, err := hawk.New(options)
if err != nil {
log.Fatal(err)
}
go catcher.Run()
defer catcher.Stop()
err = catcher.Catch(fmt.Errorf("manual exception without context"))
if err != nil {
catcher.Stop()
log.Fatal(err)
}
err = catcher.Catch(fmt.Errorf("manual exception with context"),
hawk.WithContext(struct{ Timestamp string }{Timestamp: strconv.Itoa(int(time.Now().Unix()))}),
hawk.WithUser(hawk.AffectedUser{Id: "uid", Name: "N0str"}),
hawk.WithRelease("v-3.7"),
)
if err != nil {
catcher.Stop()
log.Fatal(err)
}
// panic
var s []interface{}
fmt.Println(s[10])
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c
}
About CodeX
CodeX is a team of digital specialists around the world interested in building high-quality open source products on a global market. We are open for young people who want to constantly improve their skills and grow professionally with experiments in cutting-edge technologies.
🌐 | Join 👋 | ||
---|---|---|---|
codex.so | codex.so/join | @codex_team | @codex_team |
License
MIT
# Packages
No description provided by the author
# Functions
No description provided by the author
New returns new Catcher instance with provided access token and default URL.
NewHTTPSender returns new HTTPSender instant with default address.
NewWebsocketSender returns new WebsocketSender instant with default address.
No description provided by the author
No description provided by the author
No description provided by the author
# Constants
CatcherType is the type of this Catcher.
DefaultMaxBulkSize is default max amount of errors that can be sent at once.
DefaultMaxInterval is default max time interval to wait for errors before sending them.
DefaultSourceCodeLines is default number of source code lines before and after the line with error that will be reported.
No description provided by the author
DefaultURL is the default Hawk URL to send errors.
No description provided by the author
No description provided by the author
# Variables
ErrEmptyBacktrace is returned if getBacktrace collected empty backtrace.
ErrEmptyURL is returned if an empty URL was provided in SetURL func.
# Structs
No description provided by the author
Backtrace contains information about the function calls that caused the error.
Catcher collects information about errors and sends them to Hawk.
ErrorReport is a report about an error that is sent to Hawk.
HawkOptions is used to setup Hawk Catcher.
HTTPSender is a Sender implementation thar sends errors via http.Client.
No description provided by the author
Payload is the information about the error.
SourceCode contains the line which caused the error, the previous and the next lines.
No description provided by the author
WebsocketSender is a Sender implementation thar sends errors via websockets.
No description provided by the author
# Type aliases
No description provided by the author
No description provided by the author