Skip to content

Commit 9dd995a

Browse files
authored
Merge pull request #20 from imagekit-developer/release-please--branches--master--changes--next
release: 2.6.0
2 parents abdeb07 + 413b12a commit 9dd995a

12 files changed

Lines changed: 274 additions & 43 deletions

File tree

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "2.5.0"
2+
".": "2.6.0"
33
}

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 48
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc/imagekit-ad6dd3b4acf289708568a12574b997503059a47c4a4ca5ffefe64f40f3d3dbf3.yml
3-
openapi_spec_hash: 7c103e2dff0edcbeea82057e62f58d4d
4-
config_hash: 94f48fd13b7d41b8b6a203a3a8cee9ed
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc/imagekit-b9cc1f62fca41c286295001551cbe902d6b2f30ab775d84e549eb5affc0186ec.yml
3+
openapi_spec_hash: f3790446521a8f846e2e7249313de100
4+
config_hash: c5a7aed248c5d9ad5cd42e56fdd62c12

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 2.6.0 (2026-05-17)
4+
5+
Full Changelog: [v2.5.0...v2.6.0](https://github.com/imagekit-developer/imagekit-go/compare/v2.5.0...v2.6.0)
6+
7+
### Features
8+
9+
* **client:** optimize json encoder for internal types ([33c708e](https://github.com/imagekit-developer/imagekit-go/commit/33c708ed32562ccf0e16a736e77573d4c1b9b204))
10+
311
## 2.5.0 (2026-05-13)
412

513
Full Changelog: [v2.4.0...v2.5.0](https://github.com/imagekit-developer/imagekit-go/compare/v2.4.0...v2.5.0)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Or to pin the version:
5959
<!-- x-release-please-start-version -->
6060

6161
```sh
62-
go get -u 'github.com/imagekit-developer/imagekit-go/v2@v2.5.0'
62+
go get -u 'github.com/imagekit-developer/imagekit-go/v2@v2.6.0'
6363
```
6464

6565
<!-- x-release-please-end -->

internal/encoding/json/encode.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,21 @@ import (
173173
// JSON cannot represent cyclic data structures and Marshal does not
174174
// handle them. Passing cyclic structures to Marshal will result in
175175
// an error.
176-
func Marshal(v any) ([]byte, error) {
176+
// EDIT(begin): add optimization options
177+
func Marshal(v any, opts ...Option) ([]byte, error) {
178+
// EDIT(end): add optimization options
177179
e := newEncodeState()
178180
defer encodeStatePool.Put(e)
179181

180-
// SHIM(begin): don't escape HTML by default
181-
err := e.marshal(v, encOpts{escapeHTML: shims.EscapeHTMLByDefault})
182+
// EDIT(begin): don't escape HTML by default, and apply options
183+
encOpts := encOpts{escapeHTML: shims.EscapeHTMLByDefault}
184+
if opts != nil {
185+
encOpts = encOpts.apply(opts...)
186+
}
187+
err := e.marshal(v, encOpts)
182188
// ORIGINAL:
183189
// err := e.marshal(v, encOpts{escapeHTML: true})
184-
// SHIM(end)
190+
// EDIT(end)
185191
if err != nil {
186192
return nil, err
187193
}
@@ -352,6 +358,9 @@ type encOpts struct {
352358
// EDIT(begin): save the timefmt
353359
timefmt string
354360
// EDIT(end)
361+
// EDIT(begin): add optimization to skip compaction
362+
skipCompaction bool
363+
// EDIT(end)
355364
}
356365

357366
type encoderFunc func(e *encodeState, v reflect.Value, opts encOpts)
@@ -483,7 +492,7 @@ func marshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) {
483492
if err == nil {
484493
e.Grow(len(b))
485494
out := e.AvailableBuffer()
486-
out, err = appendCompact(out, b, opts.escapeHTML)
495+
out, err = appendCompact(out, b, opts)
487496
e.Buffer.Write(out)
488497
}
489498
if err != nil {
@@ -509,7 +518,7 @@ func addrMarshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) {
509518
if err == nil {
510519
e.Grow(len(b))
511520
out := e.AvailableBuffer()
512-
out, err = appendCompact(out, b, opts.escapeHTML)
521+
out, err = appendCompact(out, b, opts)
513522
e.Buffer.Write(out)
514523
}
515524
if err != nil {

internal/encoding/json/indent.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
package json
66

7-
import "bytes"
7+
import (
8+
"bytes"
9+
)
810

911
// HTMLEscape appends to dst the JSON-encoded src with <, >, &, U+2028 and U+2029
1012
// characters inside string literals changed to \u003c, \u003e, \u0026, \u2028, \u2029
@@ -41,12 +43,21 @@ func appendHTMLEscape(dst, src []byte) []byte {
4143
func Compact(dst *bytes.Buffer, src []byte) error {
4244
dst.Grow(len(src))
4345
b := dst.AvailableBuffer()
44-
b, err := appendCompact(b, src, false)
46+
b, err := appendCompact(b, src, encOpts{})
4547
dst.Write(b)
4648
return err
4749
}
4850

49-
func appendCompact(dst, src []byte, escape bool) ([]byte, error) {
51+
func appendCompact(dst, src []byte, opts encOpts) ([]byte, error) {
52+
// EDIT(begin): optimize for skipCompaction
53+
if opts.skipCompaction {
54+
dst = append(dst, src...)
55+
return dst, nil
56+
}
57+
58+
escape := opts.escapeHTML
59+
// EDIT(end)
60+
5061
origLen := len(dst)
5162
scan := newScanner()
5263
defer freeScanner(scan)

internal/encoding/json/opt.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// EDIT(begin): add custom options for JSON encoding
2+
package json
3+
4+
type Option func(*encOpts)
5+
6+
// Every time a sub-type of [json.Marshaler] is encountered,
7+
// skip a redundant and costly compaction step, trust it to self-compact.
8+
//
9+
// This is a divergence from the standard library behavior, and is only guaranteed
10+
// safe with SDK types.
11+
func WithSkipCompaction(b bool) Option {
12+
return func(eos *encOpts) {
13+
eos.skipCompaction = true
14+
}
15+
}
16+
17+
func (eos encOpts) apply(opts ...Option) encOpts {
18+
for _, opt := range opts {
19+
opt(&eos)
20+
}
21+
return eos
22+
}
23+
24+
// EDIT(end)

internal/encoding/json/stream.go

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package json
66

77
import (
88
"bytes"
9-
"errors"
109
"io"
1110
)
1211

@@ -253,30 +252,34 @@ func (enc *Encoder) SetEscapeHTML(on bool) {
253252
enc.escapeHTML = on
254253
}
255254

256-
// RawMessage is a raw encoded JSON value.
257-
// It implements [Marshaler] and [Unmarshaler] and can
258-
// be used to delay JSON decoding or precompute a JSON encoding.
259-
type RawMessage []byte
260-
261-
// MarshalJSON returns m as the JSON encoding of m.
262-
func (m RawMessage) MarshalJSON() ([]byte, error) {
263-
if m == nil {
264-
return []byte("null"), nil
265-
}
266-
return m, nil
267-
}
268-
269-
// UnmarshalJSON sets *m to a copy of data.
270-
func (m *RawMessage) UnmarshalJSON(data []byte) error {
271-
if m == nil {
272-
return errors.New("json.RawMessage: UnmarshalJSON on nil pointer")
273-
}
274-
*m = append((*m)[0:0], data...)
275-
return nil
276-
}
277-
278-
var _ Marshaler = (*RawMessage)(nil)
279-
var _ Unmarshaler = (*RawMessage)(nil)
255+
// EDIT(begin): remove RawMessage
256+
//
257+
// // RawMessage is a raw encoded JSON value.
258+
// // It implements [Marshaler] and [Unmarshaler] and can
259+
// // be used to delay JSON decoding or precompute a JSON encoding.
260+
// type RawMessage []byte
261+
//
262+
// // MarshalJSON returns m as the JSON encoding of m.
263+
// func (m RawMessage) MarshalJSON() ([]byte, error) {
264+
// if m == nil {
265+
// return []byte("null"), nil
266+
// }
267+
// return m, nil
268+
// }
269+
//
270+
// // UnmarshalJSON sets *m to a copy of data.
271+
// func (m *RawMessage) UnmarshalJSON(data []byte) error {
272+
// if m == nil {
273+
// return errors.New("json.RawMessage: UnmarshalJSON on nil pointer")
274+
// }
275+
// *m = append((*m)[0:0], data...)
276+
// return nil
277+
// }
278+
//
279+
// var _ Marshaler = (*RawMessage)(nil)
280+
// var _ Unmarshaler = (*RawMessage)(nil)
281+
//
282+
// EDIT(end)
280283

281284
// A Token holds a value of one of these types:
282285
//

internal/encoding/json/time.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func timeMarshalEncoder(e *encodeState, v reflect.Value, opts encOpts) bool {
5050
if b != nil {
5151
e.Grow(len(b))
5252
out := e.AvailableBuffer()
53-
out, _ = appendCompact(out, b, opts.escapeHTML)
53+
out, _ = appendCompact(out, b, opts)
5454
e.Buffer.Write(out)
5555
return true
5656
}

internal/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
package internal
44

5-
const PackageVersion = "2.5.0" // x-release-please-version
5+
const PackageVersion = "2.6.0" // x-release-please-version

0 commit comments

Comments
 (0)