Skip to content

Commit

Permalink
Updated changelog and notifier version
Browse files Browse the repository at this point in the history
  • Loading branch information
chimanjain committed Dec 14, 2021
1 parent aaa012b commit 05652f2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 34 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## master

## [v5.2.0][v5.2.0] (December 13, 2021)

* Deprecated `NewMiddleware` func and replaced with `New` func in gin middleware ([#224](https://github.com/airbrake/gobrake/pull/224))

* Used [Apex/log](https://github.com/apex/log) severity levels instead of custom defined severity levels ([#225](https://github.com/airbrake/gobrake/pull/225))

## [v5.1.1][v5.1.1] (December 1, 2021)

* Updated notifier version
Expand Down Expand Up @@ -111,3 +117,4 @@ Features:
[v5.0.4]: https://github.com/airbrake/gobrake/releases/tag/v5.0.4
[v5.1.0]: https://github.com/airbrake/gobrake/releases/tag/v5.1.0
[v5.1.1]: https://github.com/airbrake/gobrake/releases/tag/v5.1.1
[v5.2.0]: https://github.com/airbrake/gobrake/releases/tag/v5.2.0
34 changes: 1 addition & 33 deletions gin/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gin

import (
"context"
"sync"

"github.com/airbrake/gobrake/v5"

Expand All @@ -23,36 +22,5 @@ func New(engine *gin.Engine, notifier *gobrake.Notifier) func(c *gin.Context) {

// This function is deprecated. Please use New() function instead
func NewMiddleware(engine *gin.Engine, notifier *gobrake.Notifier) func(c *gin.Context) {
return func(c *gin.Context) {
routeName := routeName(c, engine)
_, metric := gobrake.NewRouteMetric(context.TODO(), c.Request.Method, routeName)

c.Next()

metric.StatusCode = c.Writer.Status()
_ = notifier.Routes.Notify(context.TODO(), metric)
}
}

func routeName(c *gin.Context, engine *gin.Engine) string {
initPathMap(engine)
route, ok := pathMap[c.HandlerName()]
if ok {
return route
}
return "UNKNOWN"
}

var (
pathMapOnce sync.Once
pathMap map[string]string
)

func initPathMap(engine *gin.Engine) {
pathMapOnce.Do(func() {
pathMap = make(map[string]string)
for _, ri := range engine.Routes() {
pathMap[ri.Handler] = ri.Path
}
})
return New(engine, notifier)
}
2 changes: 1 addition & 1 deletion notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

const notifierName = "gobrake"
const notifierVersion = "5.1.1"
const notifierVersion = "5.2.0"
const userAgent = notifierName + "/" + notifierVersion

const waitTimeout = 5 * time.Second
Expand Down

0 comments on commit 05652f2

Please sign in to comment.