https://github.com/codex-team/hawk.go
Hawk catcher for Golang
https://github.com/codex-team/hawk.go
Last synced: 3 months ago
JSON representation
Hawk catcher for Golang
- Host: GitHub
- URL: https://github.com/codex-team/hawk.go
- Owner: codex-team
- Created: 2018-12-19T23:35:51.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-02-23T14:00:12.000Z (almost 4 years ago)
- Last Synced: 2025-09-04T08:54:24.727Z (4 months ago)
- Language: Go
- Size: 55.7 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Hawk catcher for Golang
Golang errors catcher for [Hawk.so](https://hawk.so)
## Installation
### Go Get
```golang
go get github.com/codex-team/hawk.go
```
## Usage
Initiate Hawk catcher
```
options := hawk.DefaultHawkOptions()
options.AccessToken = ""
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
```golang
package main
import (
"fmt"
"log"
"os"
"os/signal"
"strconv"
"syscall"
"time"
"github.com/codex-team/hawk.go"
)
func main() {
options := hawk.DefaultHawkOptions()
options.AccessToken = ""
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](https://codex.so/join) for young people who want to constantly improve their skills and grow professionally with experiments in cutting-edge technologies.
| 🌐 | Join 👋 | Twitter | Instagram |
| -- | -- | -- | -- |
| [codex.so](https://codex.so) | [codex.so/join](https://codex.so/join) |[@codex_team](http://twitter.com/codex_team) | [@codex_team](http://instagram.com/codex_team) |
## License
MIT