From a1714f2fd72fce81d92fb360dddb5b1eb001d2c9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 4 Mar 2025 20:44:32 +0100 Subject: [PATCH 1/5] chore(deps): bump golang.org/x/net from 0.26.0 to 0.33.0 in /example (#39) Bumps [golang.org/x/net](https://github.com/golang/net) from 0.26.0 to 0.33.0. - [Commits](https://github.com/golang/net/compare/v0.26.0...v0.33.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- example/go.mod | 2 +- example/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example/go.mod b/example/go.mod index 9e96bcc..5ad3e14 100644 --- a/example/go.mod +++ b/example/go.mod @@ -42,7 +42,7 @@ require ( go.opentelemetry.io/otel/trace v1.29.0 // indirect golang.org/x/arch v0.8.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/net v0.26.0 // indirect + golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect golang.org/x/text v0.21.0 // indirect google.golang.org/protobuf v1.34.2 // indirect diff --git a/example/go.sum b/example/go.sum index 1524a4f..a653c64 100644 --- a/example/go.sum +++ b/example/go.sum @@ -95,8 +95,8 @@ golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= +golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= From 619096adca5bbf1494944387021c8950cc43df2f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 4 Mar 2025 20:44:42 +0100 Subject: [PATCH 2/5] chore(deps): bump golang.org/x/net from 0.26.0 to 0.33.0 (#38) Bumps [golang.org/x/net](https://github.com/golang/net) from 0.26.0 to 0.33.0. - [Commits](https://github.com/golang/net/compare/v0.26.0...v0.33.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 5826468..9584999 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( go.opentelemetry.io/otel v1.29.0 // indirect golang.org/x/arch v0.8.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/net v0.26.0 // indirect + golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect golang.org/x/text v0.21.0 // indirect google.golang.org/protobuf v1.34.2 // indirect diff --git a/go.sum b/go.sum index 41277d1..d8cb8e4 100644 --- a/go.sum +++ b/go.sum @@ -81,8 +81,8 @@ golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= +golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= From 459172cc27b78bb4815081f9975295335cb3ef9a Mon Sep 17 00:00:00 2001 From: Paul Laffitte Date: Wed, 12 Mar 2025 18:33:17 +0100 Subject: [PATCH 3/5] fix: make the Ignore filter really ignoring instead of accepting (#40) * fix: make the Ignore filter really ignoring instead of accepting * refactor: modernize filters using slices functions --- filters.go | 51 ++++++++------------------------------------------- 1 file changed, 8 insertions(+), 43 deletions(-) diff --git a/filters.go b/filters.go index d5ed5a7..f596b75 100644 --- a/filters.go +++ b/filters.go @@ -2,6 +2,7 @@ package sloggin import ( "regexp" + "slices" "strings" "github.com/gin-gonic/gin" @@ -11,7 +12,7 @@ type Filter func(ctx *gin.Context) bool // Basic func Accept(filter Filter) Filter { return filter } -func Ignore(filter Filter) Filter { return filter } +func Ignore(filter Filter) Filter { return func(ctx *gin.Context) bool { return !filter(ctx) } } // Method func AcceptMethod(methods ...string) Filter { @@ -45,25 +46,13 @@ func IgnoreMethod(methods ...string) Filter { // Status func AcceptStatus(statuses ...int) Filter { return func(c *gin.Context) bool { - for _, status := range statuses { - if status == c.Writer.Status() { - return true - } - } - - return false + return slices.Contains(statuses, c.Writer.Status()) } } func IgnoreStatus(statuses ...int) Filter { return func(c *gin.Context) bool { - for _, status := range statuses { - if status == c.Writer.Status() { - return false - } - } - - return true + return !slices.Contains(statuses, c.Writer.Status()) } } @@ -110,25 +99,13 @@ func IgnoreStatusLessThanOrEqual(status int) Filter { // Path func AcceptPath(urls ...string) Filter { return func(c *gin.Context) bool { - for _, url := range urls { - if c.Request.URL.Path == url { - return true - } - } - - return false + return slices.Contains(urls, c.Request.URL.Path) } } func IgnorePath(urls ...string) Filter { return func(c *gin.Context) bool { - for _, url := range urls { - if c.Request.URL.Path == url { - return false - } - } - - return true + return !slices.Contains(urls, c.Request.URL.Path) } } @@ -231,25 +208,13 @@ func IgnorePathMatch(regs ...regexp.Regexp) Filter { // Host func AcceptHost(hosts ...string) Filter { return func(c *gin.Context) bool { - for _, host := range hosts { - if c.Request.URL.Host == host { - return true - } - } - - return false + return slices.Contains(hosts, c.Request.URL.Host) } } func IgnoreHost(hosts ...string) Filter { return func(c *gin.Context) bool { - for _, host := range hosts { - if c.Request.URL.Host == host { - return false - } - } - - return true + return !slices.Contains(hosts, c.Request.URL.Host) } } From 8dd8aece8a5c2459d84df17b1be166cf6c860f0d Mon Sep 17 00:00:00 2001 From: Paul Laffitte Date: Wed, 12 Mar 2025 19:06:04 +0100 Subject: [PATCH 4/5] fix: default error messages (#42) In some cases (a 404 not found error for instance) there is no message attached to the error. This allows to always provide a message alongside error logs. --- middleware.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/middleware.go b/middleware.go index b251a52..076a43a 100644 --- a/middleware.go +++ b/middleware.go @@ -2,6 +2,7 @@ package sloggin import ( "context" + "fmt" "log/slog" "net/http" "strings" @@ -250,9 +251,15 @@ func NewWithConfig(logger *slog.Logger, config Config) gin.HandlerFunc { if status >= http.StatusBadRequest && status < http.StatusInternalServerError { level = config.ClientErrorLevel msg = c.Errors.String() + if msg == "" { + msg = fmt.Sprintf("HTTP error: %d %s", status, strings.ToLower(http.StatusText(status))) + } } else if status >= http.StatusInternalServerError { level = config.ServerErrorLevel msg = c.Errors.String() + if msg == "" { + msg = fmt.Sprintf("HTTP error: %d %s", status, strings.ToLower(http.StatusText(status))) + } } logger.LogAttrs(c.Request.Context(), level, msg, attributes...) From ae7a954ab856629391e723cd9d39ff81eeeace38 Mon Sep 17 00:00:00 2001 From: samber Date: Wed, 12 Mar 2025 18:07:57 +0000 Subject: [PATCH 5/5] bump v1.15.0 --- go.mod | 3 ++- go.sum | 4 ++-- main_test.go | 11 ----------- 3 files changed, 4 insertions(+), 14 deletions(-) delete mode 100644 main_test.go diff --git a/go.mod b/go.mod index 9584999..1b1537b 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/goccy/go-json v0.10.3 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.8 // indirect + github.com/kr/pretty v0.1.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect @@ -30,6 +31,7 @@ require ( golang.org/x/sys v0.28.0 // indirect golang.org/x/text v0.21.0 // indirect google.golang.org/protobuf v1.34.2 // indirect + gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) @@ -37,5 +39,4 @@ require ( github.com/gin-gonic/gin v1.10.0 github.com/google/uuid v1.6.0 go.opentelemetry.io/otel/trace v1.29.0 - go.uber.org/goleak v1.3.0 ) diff --git a/go.sum b/go.sum index d8cb8e4..cfdc680 100644 --- a/go.sum +++ b/go.sum @@ -39,6 +39,8 @@ github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZY github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= @@ -74,8 +76,6 @@ go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw= go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8= go.opentelemetry.io/otel/trace v1.29.0 h1:J/8ZNK4XgR7a21DZUAsbF8pZ5Jcw1VhACmnYt39JTi4= go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ= -go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= -go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= diff --git a/main_test.go b/main_test.go deleted file mode 100644 index 7ee6f9c..0000000 --- a/main_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package sloggin - -import ( - "testing" - - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) -}