Skip to content

Commit 7822f5a

Browse files
fix: use slices.Concat instead of sometimes modifying r.Options
1 parent 6cfe89f commit 7822f5a

15 files changed

Lines changed: 59 additions & 44 deletions

accountorigin.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99
"fmt"
1010
"net/http"
11+
"slices"
1112

1213
"github.com/imagekit-developer/imagekit-go/internal/apijson"
1314
shimjson "github.com/imagekit-developer/imagekit-go/internal/encoding/json"
@@ -40,7 +41,7 @@ func NewAccountOriginService(opts ...option.RequestOption) (r AccountOriginServi
4041
// **Note:** This API is currently in beta.
4142
// Creates a new origin and returns the origin object.
4243
func (r *AccountOriginService) New(ctx context.Context, body AccountOriginNewParams, opts ...option.RequestOption) (res *OriginResponseUnion, err error) {
43-
opts = append(r.Options[:], opts...)
44+
opts = slices.Concat(r.Options, opts)
4445
path := "v1/accounts/origins"
4546
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
4647
return
@@ -49,7 +50,7 @@ func (r *AccountOriginService) New(ctx context.Context, body AccountOriginNewPar
4950
// **Note:** This API is currently in beta.
5051
// Updates the origin identified by `id` and returns the updated origin object.
5152
func (r *AccountOriginService) Update(ctx context.Context, id string, body AccountOriginUpdateParams, opts ...option.RequestOption) (res *OriginResponseUnion, err error) {
52-
opts = append(r.Options[:], opts...)
53+
opts = slices.Concat(r.Options, opts)
5354
if id == "" {
5455
err = errors.New("missing required id parameter")
5556
return
@@ -62,7 +63,7 @@ func (r *AccountOriginService) Update(ctx context.Context, id string, body Accou
6263
// **Note:** This API is currently in beta.
6364
// Returns an array of all configured origins for the current account.
6465
func (r *AccountOriginService) List(ctx context.Context, opts ...option.RequestOption) (res *[]OriginResponseUnion, err error) {
65-
opts = append(r.Options[:], opts...)
66+
opts = slices.Concat(r.Options, opts)
6667
path := "v1/accounts/origins"
6768
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
6869
return
@@ -72,7 +73,7 @@ func (r *AccountOriginService) List(ctx context.Context, opts ...option.RequestO
7273
// Permanently removes the origin identified by `id`. If the origin is in use by
7374
// any URL‑endpoints, the API will return an error.
7475
func (r *AccountOriginService) Delete(ctx context.Context, id string, opts ...option.RequestOption) (err error) {
75-
opts = append(r.Options[:], opts...)
76+
opts = slices.Concat(r.Options, opts)
7677
opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
7778
if id == "" {
7879
err = errors.New("missing required id parameter")
@@ -86,7 +87,7 @@ func (r *AccountOriginService) Delete(ctx context.Context, id string, opts ...op
8687
// **Note:** This API is currently in beta.
8788
// Retrieves the origin identified by `id`.
8889
func (r *AccountOriginService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *OriginResponseUnion, err error) {
89-
opts = append(r.Options[:], opts...)
90+
opts = slices.Concat(r.Options, opts)
9091
if id == "" {
9192
err = errors.New("missing required id parameter")
9293
return

accounturlendpoint.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99
"fmt"
1010
"net/http"
11+
"slices"
1112

1213
"github.com/imagekit-developer/imagekit-go/internal/apijson"
1314
shimjson "github.com/imagekit-developer/imagekit-go/internal/encoding/json"
@@ -40,7 +41,7 @@ func NewAccountURLEndpointService(opts ...option.RequestOption) (r AccountURLEnd
4041
// **Note:** This API is currently in beta.
4142
// Creates a new URL‑endpoint and returns the resulting object.
4243
func (r *AccountURLEndpointService) New(ctx context.Context, body AccountURLEndpointNewParams, opts ...option.RequestOption) (res *URLEndpointResponse, err error) {
43-
opts = append(r.Options[:], opts...)
44+
opts = slices.Concat(r.Options, opts)
4445
path := "v1/accounts/url-endpoints"
4546
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
4647
return
@@ -49,7 +50,7 @@ func (r *AccountURLEndpointService) New(ctx context.Context, body AccountURLEndp
4950
// **Note:** This API is currently in beta.
5051
// Updates the URL‑endpoint identified by `id` and returns the updated object.
5152
func (r *AccountURLEndpointService) Update(ctx context.Context, id string, body AccountURLEndpointUpdateParams, opts ...option.RequestOption) (res *URLEndpointResponse, err error) {
52-
opts = append(r.Options[:], opts...)
53+
opts = slices.Concat(r.Options, opts)
5354
if id == "" {
5455
err = errors.New("missing required id parameter")
5556
return
@@ -63,7 +64,7 @@ func (r *AccountURLEndpointService) Update(ctx context.Context, id string, body
6364
// Returns an array of all URL‑endpoints configured including the default
6465
// URL-endpoint generated by ImageKit during account creation.
6566
func (r *AccountURLEndpointService) List(ctx context.Context, opts ...option.RequestOption) (res *[]URLEndpointResponse, err error) {
66-
opts = append(r.Options[:], opts...)
67+
opts = slices.Concat(r.Options, opts)
6768
path := "v1/accounts/url-endpoints"
6869
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
6970
return
@@ -73,7 +74,7 @@ func (r *AccountURLEndpointService) List(ctx context.Context, opts ...option.Req
7374
// Deletes the URL‑endpoint identified by `id`. You cannot delete the default
7475
// URL‑endpoint created by ImageKit during account creation.
7576
func (r *AccountURLEndpointService) Delete(ctx context.Context, id string, opts ...option.RequestOption) (err error) {
76-
opts = append(r.Options[:], opts...)
77+
opts = slices.Concat(r.Options, opts)
7778
opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
7879
if id == "" {
7980
err = errors.New("missing required id parameter")
@@ -87,7 +88,7 @@ func (r *AccountURLEndpointService) Delete(ctx context.Context, id string, opts
8788
// **Note:** This API is currently in beta.
8889
// Retrieves the URL‑endpoint identified by `id`.
8990
func (r *AccountURLEndpointService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *URLEndpointResponse, err error) {
90-
opts = append(r.Options[:], opts...)
91+
opts = slices.Concat(r.Options, opts)
9192
if id == "" {
9293
err = errors.New("missing required id parameter")
9394
return

accountusage.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
"net/url"
9+
"slices"
910
"time"
1011

1112
"github.com/imagekit-developer/imagekit-go/internal/apijson"
@@ -39,7 +40,7 @@ func NewAccountUsageService(opts ...option.RequestOption) (r AccountUsageService
3940
// other words, the data covers the period starting from the specified start date
4041
// up to, but not including, the end date.
4142
func (r *AccountUsageService) Get(ctx context.Context, query AccountUsageGetParams, opts ...option.RequestOption) (res *AccountUsageGetResponse, err error) {
42-
opts = append(r.Options[:], opts...)
43+
opts = slices.Concat(r.Options, opts)
4344
path := "v1/accounts/usage"
4445
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
4546
return

asset.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"encoding/json"
88
"net/http"
99
"net/url"
10+
"slices"
1011
"time"
1112

1213
"github.com/imagekit-developer/imagekit-go/internal/apijson"
@@ -41,7 +42,7 @@ func NewAssetService(opts ...option.RequestOption) (r AssetService) {
4142
// by generating a query string in a Lucene-like syntax and provide this generated
4243
// string as the value of the `searchQuery`.
4344
func (r *AssetService) List(ctx context.Context, query AssetListParams, opts ...option.RequestOption) (res *[]AssetListResponseUnion, err error) {
44-
opts = append(r.Options[:], opts...)
45+
opts = slices.Concat(r.Options, opts)
4546
path := "v1/files"
4647
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
4748
return

betav2file.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io"
99
"mime/multipart"
1010
"net/http"
11+
"slices"
1112

1213
"github.com/imagekit-developer/imagekit-go/internal/apiform"
1314
"github.com/imagekit-developer/imagekit-go/internal/apijson"
@@ -66,7 +67,7 @@ func NewBetaV2FileService(opts ...option.RequestOption) (r BetaV2FileService) {
6667
// - [Quick start guides](/docs/quick-start-guides) for various frameworks and
6768
// technologies.
6869
func (r *BetaV2FileService) Upload(ctx context.Context, body BetaV2FileUploadParams, opts ...option.RequestOption) (res *BetaV2FileUploadResponse, err error) {
69-
opts = append(r.Options[:], opts...)
70+
opts = slices.Concat(r.Options, opts)
7071
opts = append([]option.RequestOption{option.WithBaseURL("https://upload.imagekit.io/")}, opts...)
7172
path := "api/v2/files/upload"
7273
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)

cacheinvalidation.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"fmt"
99
"net/http"
10+
"slices"
1011

1112
"github.com/imagekit-developer/imagekit-go/internal/apijson"
1213
"github.com/imagekit-developer/imagekit-go/internal/requestconfig"
@@ -38,15 +39,15 @@ func NewCacheInvalidationService(opts ...option.RequestOption) (r CacheInvalidat
3839
// Purge cache is an asynchronous process and it may take some time to reflect the
3940
// changes.
4041
func (r *CacheInvalidationService) New(ctx context.Context, body CacheInvalidationNewParams, opts ...option.RequestOption) (res *CacheInvalidationNewResponse, err error) {
41-
opts = append(r.Options[:], opts...)
42+
opts = slices.Concat(r.Options, opts)
4243
path := "v1/files/purge"
4344
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
4445
return
4546
}
4647

4748
// This API returns the status of a purge cache request.
4849
func (r *CacheInvalidationService) Get(ctx context.Context, requestID string, opts ...option.RequestOption) (res *CacheInvalidationGetResponse, err error) {
49-
opts = append(r.Options[:], opts...)
50+
opts = slices.Concat(r.Options, opts)
5051
if requestID == "" {
5152
err = errors.New("missing required requestId parameter")
5253
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/imagekit-developer/imagekit-go/internal/requestconfig"
1112
"github.com/imagekit-developer/imagekit-go/option"
@@ -101,7 +102,7 @@ func NewClient(opts ...option.RequestOption) (r Client) {
101102
// For even greater flexibility, see [option.WithResponseInto] and
102103
// [option.WithResponseBodyInto].
103104
func (r *Client) Execute(ctx context.Context, method string, path string, params any, res any, opts ...option.RequestOption) error {
104-
opts = append(r.Options, opts...)
105+
opts = slices.Concat(r.Options, opts)
105106
return requestconfig.ExecuteNewRequest(ctx, method, path, params, res, opts...)
106107
}
107108

custommetadatafield.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"net/http"
1111
"net/url"
12+
"slices"
1213

1314
"github.com/imagekit-developer/imagekit-go/internal/apijson"
1415
"github.com/imagekit-developer/imagekit-go/internal/apiquery"
@@ -42,15 +43,15 @@ func NewCustomMetadataFieldService(opts ...option.RequestOption) (r CustomMetada
4243
// on the assets. The value of a field for an asset can be set using the media
4344
// library UI or programmatically through upload or update assets API.
4445
func (r *CustomMetadataFieldService) New(ctx context.Context, body CustomMetadataFieldNewParams, opts ...option.RequestOption) (res *CustomMetadataField, err error) {
45-
opts = append(r.Options[:], opts...)
46+
opts = slices.Concat(r.Options, opts)
4647
path := "v1/customMetadataFields"
4748
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
4849
return
4950
}
5051

5152
// This API updates the label or schema of an existing custom metadata field.
5253
func (r *CustomMetadataFieldService) Update(ctx context.Context, id string, body CustomMetadataFieldUpdateParams, opts ...option.RequestOption) (res *CustomMetadataField, err error) {
53-
opts = append(r.Options[:], opts...)
54+
opts = slices.Concat(r.Options, opts)
5455
if id == "" {
5556
err = errors.New("missing required id parameter")
5657
return
@@ -64,7 +65,7 @@ func (r *CustomMetadataFieldService) Update(ctx context.Context, id string, body
6465
// the API returns only non deleted field objects, but you can include deleted
6566
// fields in the API response.
6667
func (r *CustomMetadataFieldService) List(ctx context.Context, query CustomMetadataFieldListParams, opts ...option.RequestOption) (res *[]CustomMetadataField, err error) {
67-
opts = append(r.Options[:], opts...)
68+
opts = slices.Concat(r.Options, opts)
6869
path := "v1/customMetadataFields"
6970
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
7071
return
@@ -73,7 +74,7 @@ func (r *CustomMetadataFieldService) List(ctx context.Context, query CustomMetad
7374
// This API deletes a custom metadata field. Even after deleting a custom metadata
7475
// field, you cannot create any new custom metadata field with the same name.
7576
func (r *CustomMetadataFieldService) Delete(ctx context.Context, id string, opts ...option.RequestOption) (res *CustomMetadataFieldDeleteResponse, err error) {
76-
opts = append(r.Options[:], opts...)
77+
opts = slices.Concat(r.Options, opts)
7778
if id == "" {
7879
err = errors.New("missing required id parameter")
7980
return

file.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"io"
1212
"mime/multipart"
1313
"net/http"
14+
"slices"
1415
"time"
1516

1617
"github.com/imagekit-developer/imagekit-go/internal/apiform"
@@ -53,7 +54,7 @@ func NewFileService(opts ...option.RequestOption) (r FileService) {
5354
// You can update `tags`, `customCoordinates`, `customMetadata`, publication
5455
// status, remove existing `AITags` and apply extensions using this API.
5556
func (r *FileService) Update(ctx context.Context, fileID string, body FileUpdateParams, opts ...option.RequestOption) (res *FileUpdateResponse, err error) {
56-
opts = append(r.Options[:], opts...)
57+
opts = slices.Concat(r.Options, opts)
5758
if fileID == "" {
5859
err = errors.New("missing required fileId parameter")
5960
return
@@ -69,7 +70,7 @@ func (r *FileService) Update(ctx context.Context, fileID string, body FileUpdate
6970
// the response is cached. Deleting a file does not purge the cache. You can purge
7071
// the cache using purge cache API.
7172
func (r *FileService) Delete(ctx context.Context, fileID string, opts ...option.RequestOption) (err error) {
72-
opts = append(r.Options[:], opts...)
73+
opts = slices.Concat(r.Options, opts)
7374
opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
7475
if fileID == "" {
7576
err = errors.New("missing required fileId parameter")
@@ -86,7 +87,7 @@ func (r *FileService) Delete(ctx context.Context, fileID string, opts ...option.
8687
// the source file and its versions (if `includeFileVersions` is set to true) will
8788
// be appended to the destination file version history.
8889
func (r *FileService) Copy(ctx context.Context, body FileCopyParams, opts ...option.RequestOption) (res *FileCopyResponse, err error) {
89-
opts = append(r.Options[:], opts...)
90+
opts = slices.Concat(r.Options, opts)
9091
path := "v1/files/copy"
9192
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
9293
return
@@ -95,7 +96,7 @@ func (r *FileService) Copy(ctx context.Context, body FileCopyParams, opts ...opt
9596
// This API returns an object with details or attributes about the current version
9697
// of the file.
9798
func (r *FileService) Get(ctx context.Context, fileID string, opts ...option.RequestOption) (res *File, err error) {
98-
opts = append(r.Options[:], opts...)
99+
opts = slices.Concat(r.Options, opts)
99100
if fileID == "" {
100101
err = errors.New("missing required fileId parameter")
101102
return
@@ -110,7 +111,7 @@ func (r *FileService) Get(ctx context.Context, fileID string, opts ...option.Req
110111
// Note: If any file at the destination has the same name as the source file, then
111112
// the source file and its versions will be appended to the destination file.
112113
func (r *FileService) Move(ctx context.Context, body FileMoveParams, opts ...option.RequestOption) (res *FileMoveResponse, err error) {
113-
opts = append(r.Options[:], opts...)
114+
opts = slices.Concat(r.Options, opts)
114115
path := "v1/files/move"
115116
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
116117
return
@@ -122,7 +123,7 @@ func (r *FileService) Move(ctx context.Context, body FileMoveParams, opts ...opt
122123
// Note: The old URLs will stop working. The file/file version URLs cached on CDN
123124
// will continue to work unless a purge is requested.
124125
func (r *FileService) Rename(ctx context.Context, body FileRenameParams, opts ...option.RequestOption) (res *FileRenameResponse, err error) {
125-
opts = append(r.Options[:], opts...)
126+
opts = slices.Concat(r.Options, opts)
126127
path := "v1/files/rename"
127128
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, body, &res, opts...)
128129
return
@@ -156,7 +157,7 @@ func (r *FileService) Rename(ctx context.Context, body FileRenameParams, opts ..
156157
// - [Quick start guides](/docs/quick-start-guides) for various frameworks and
157158
// technologies.
158159
func (r *FileService) Upload(ctx context.Context, body FileUploadParams, opts ...option.RequestOption) (res *FileUploadResponse, err error) {
159-
opts = append(r.Options[:], opts...)
160+
opts = slices.Concat(r.Options, opts)
160161
opts = append([]option.RequestOption{option.WithBaseURL("https://upload.imagekit.io/")}, opts...)
161162
path := "api/v1/files/upload"
162163
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)

filebulk.go

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

910
"github.com/imagekit-developer/imagekit-go/internal/apijson"
1011
"github.com/imagekit-developer/imagekit-go/internal/requestconfig"
@@ -40,7 +41,7 @@ func NewFileBulkService(opts ...option.RequestOption) (r FileBulkService) {
4041
//
4142
// A maximum of 100 files can be deleted at a time.
4243
func (r *FileBulkService) Delete(ctx context.Context, body FileBulkDeleteParams, opts ...option.RequestOption) (res *FileBulkDeleteResponse, err error) {
43-
opts = append(r.Options[:], opts...)
44+
opts = slices.Concat(r.Options, opts)
4445
path := "v1/files/batch/deleteByFileIds"
4546
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
4647
return
@@ -49,7 +50,7 @@ func (r *FileBulkService) Delete(ctx context.Context, body FileBulkDeleteParams,
4950
// This API adds tags to multiple files in bulk. A maximum of 50 files can be
5051
// specified at a time.
5152
func (r *FileBulkService) AddTags(ctx context.Context, body FileBulkAddTagsParams, opts ...option.RequestOption) (res *FileBulkAddTagsResponse, err error) {
52-
opts = append(r.Options[:], opts...)
53+
opts = slices.Concat(r.Options, opts)
5354
path := "v1/files/addTags"
5455
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
5556
return
@@ -58,7 +59,7 @@ func (r *FileBulkService) AddTags(ctx context.Context, body FileBulkAddTagsParam
5859
// This API removes AITags from multiple files in bulk. A maximum of 50 files can
5960
// be specified at a time.
6061
func (r *FileBulkService) RemoveAITags(ctx context.Context, body FileBulkRemoveAITagsParams, opts ...option.RequestOption) (res *FileBulkRemoveAITagsResponse, err error) {
61-
opts = append(r.Options[:], opts...)
62+
opts = slices.Concat(r.Options, opts)
6263
path := "v1/files/removeAITags"
6364
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
6465
return
@@ -67,7 +68,7 @@ func (r *FileBulkService) RemoveAITags(ctx context.Context, body FileBulkRemoveA
6768
// This API removes tags from multiple files in bulk. A maximum of 50 files can be
6869
// specified at a time.
6970
func (r *FileBulkService) RemoveTags(ctx context.Context, body FileBulkRemoveTagsParams, opts ...option.RequestOption) (res *FileBulkRemoveTagsResponse, err error) {
70-
opts = append(r.Options[:], opts...)
71+
opts = slices.Concat(r.Options, opts)
7172
path := "v1/files/removeTags"
7273
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
7374
return

0 commit comments

Comments
 (0)