From 05652f20b79866c122eae94a459e12714606e48c Mon Sep 17 00:00:00 2001 From: ChimanJain <36687396+ChimanJain@users.noreply.github.com> Date: Fri, 10 Dec 2021 18:49:19 +0530 Subject: [PATCH] Updated changelog and notifier version --- CHANGELOG.md | 7 +++++++ gin/middleware.go | 34 +--------------------------------- notifier.go | 2 +- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09b20fb..8c3458d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/gin/middleware.go b/gin/middleware.go index b2a1de2..b09d2c4 100644 --- a/gin/middleware.go +++ b/gin/middleware.go @@ -2,7 +2,6 @@ package gin import ( "context" - "sync" "github.com/airbrake/gobrake/v5" @@ -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) } diff --git a/notifier.go b/notifier.go index 86ef299..eeaa211 100644 --- a/notifier.go +++ b/notifier.go @@ -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