Skip to content

Commit bf443ca

Browse files
committed
fix: use slices clone to copy options in factories
1 parent 360c04d commit bf443ca

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

pkg/middleware/auth-middleware.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package middleware
33
import (
44
"log/slog"
55
"net/http"
6+
"slices"
67

78
"github.com/bsv-blockchain/go-bsv-middleware/pkg/internal/authentication"
89
"github.com/bsv-blockchain/go-sdk/auth"
@@ -97,7 +98,7 @@ func (f *AuthMiddlewareFactory) HTTPHandler(next http.Handler) http.Handler {
9798
// This method can be useful when we have factory with default configuration for middleware,
9899
// but we want to customize it for a specific handler (for example, turn on unauthenticated access).
99100
func (f *AuthMiddlewareFactory) HTTPHandlerWithOptions(next http.Handler, opts ...func(*AuthMiddlewareConfig)) http.Handler {
100-
opts = append(f.options[:], opts...)
101+
opts = append(slices.Clone(f.options), opts...)
101102

102103
if f.wallet == nil {
103104
// In case if someone would create a factory just by calling &middleware.AuthMiddlewareFactory{}

pkg/middleware/payment_middleware.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package middleware
33
import (
44
"log/slog"
55
"net/http"
6+
"slices"
67

78
"github.com/bsv-blockchain/go-bsv-middleware/pkg/internal/payment"
89
"github.com/bsv-blockchain/go-sdk/wallet"
@@ -66,7 +67,7 @@ func (f *PaymentMiddlewareFactory) HTTPHandler(next http.Handler) http.Handler {
6667
// This method can be useful when we have factory with default configuration for middleware,
6768
// but we want to customize it for a specific handler (for example use different payment calculator).
6869
func (f *PaymentMiddlewareFactory) HTTPHandlerWithOptions(next http.Handler, opts ...func(*PaymentMiddlewareConfig)) http.Handler {
69-
opts = append(f.options[:], opts...)
70+
opts = append(slices.Clone(f.options), opts...)
7071

7172
if f.wallet == nil {
7273
// In case if someone would create a factory just by calling &middleware.PaymentMiddlewareFactory{}

0 commit comments

Comments
 (0)