Skip to content

Commit c30d79a

Browse files
fix: use slices.Concat instead of sometimes modifying r.Options
1 parent fc3b56e commit c30d79a

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

casgenerator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package casparser
55
import (
66
"context"
77
"net/http"
8+
"slices"
89

910
"github.com/CASParser/cas-parser-go/internal/apijson"
1011
"github.com/CASParser/cas-parser-go/internal/requestconfig"
@@ -36,7 +37,7 @@ func NewCasGeneratorService(opts ...option.RequestOption) (r CasGeneratorService
3637
// submitting a mailback request to the specified CAS authority. Currently only
3738
// supports KFintech, with plans to support CAMS, CDSL, and NSDL in the future.
3839
func (r *CasGeneratorService) GenerateCas(ctx context.Context, body CasGeneratorGenerateCasParams, opts ...option.RequestOption) (res *CasGeneratorGenerateCasResponse, err error) {
39-
opts = append(r.Options[:], opts...)
40+
opts = slices.Concat(r.Options, opts)
4041
path := "v4/generate"
4142
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
4243
return

casparser.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package casparser
55
import (
66
"context"
77
"net/http"
8+
"slices"
89
"time"
910

1011
"github.com/CASParser/cas-parser-go/internal/apijson"
@@ -37,7 +38,7 @@ func NewCasParserService(opts ...option.RequestOption) (r CasParserService) {
3738
// Statement) PDF files and returns data in a unified format. Use this endpoint
3839
// when you know the PDF is from CAMS or KFintech.
3940
func (r *CasParserService) CamsKfintech(ctx context.Context, body CasParserCamsKfintechParams, opts ...option.RequestOption) (res *UnifiedResponse, err error) {
40-
opts = append(r.Options[:], opts...)
41+
opts = slices.Concat(r.Options, opts)
4142
path := "v4/cams_kfintech/parse"
4243
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
4344
return
@@ -47,7 +48,7 @@ func (r *CasParserService) CamsKfintech(ctx context.Context, body CasParserCamsK
4748
// files and returns data in a unified format. Use this endpoint when you know the
4849
// PDF is from CDSL.
4950
func (r *CasParserService) Cdsl(ctx context.Context, body CasParserCdslParams, opts ...option.RequestOption) (res *UnifiedResponse, err error) {
50-
opts = append(r.Options[:], opts...)
51+
opts = slices.Concat(r.Options, opts)
5152
path := "v4/cdsl/parse"
5253
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
5354
return
@@ -57,7 +58,7 @@ func (r *CasParserService) Cdsl(ctx context.Context, body CasParserCdslParams, o
5758
// files and returns data in a unified format. Use this endpoint when you know the
5859
// PDF is from NSDL.
5960
func (r *CasParserService) Nsdl(ctx context.Context, body CasParserNsdlParams, opts ...option.RequestOption) (res *UnifiedResponse, err error) {
60-
opts = append(r.Options[:], opts...)
61+
opts = slices.Concat(r.Options, opts)
6162
path := "v4/nsdl/parse"
6263
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
6364
return
@@ -68,7 +69,7 @@ func (r *CasParserService) Nsdl(ctx context.Context, body CasParserNsdlParams, o
6869
// CAS type and transforms the data into a consistent structure regardless of the
6970
// source.
7071
func (r *CasParserService) SmartParse(ctx context.Context, body CasParserSmartParseParams, opts ...option.RequestOption) (res *UnifiedResponse, err error) {
71-
opts = append(r.Options[:], opts...)
72+
opts = slices.Concat(r.Options, opts)
7273
path := "v4/smart/parse"
7374
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
7475
return

client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"net/http"
88
"os"
9+
"slices"
910

1011
"github.com/CASParser/cas-parser-go/internal/requestconfig"
1112
"github.com/CASParser/cas-parser-go/option"
@@ -80,7 +81,7 @@ func NewClient(opts ...option.RequestOption) (r Client) {
8081
// For even greater flexibility, see [option.WithResponseInto] and
8182
// [option.WithResponseBodyInto].
8283
func (r *Client) Execute(ctx context.Context, method string, path string, params any, res any, opts ...option.RequestOption) error {
83-
opts = append(r.Options, opts...)
84+
opts = slices.Concat(r.Options, opts)
8485
return requestconfig.ExecuteNewRequest(ctx, method, path, params, res, opts...)
8586
}
8687

0 commit comments

Comments
 (0)