Skip to content

Commit edf1c79

Browse files
committed
remove superfluous 'json' from struct names in jsonpatch package
1 parent 0959a5a commit edf1c79

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

pkg/jsonpatch/patch.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,35 @@ import (
1212

1313
type Untyped = []byte
1414

15-
type JSONPatch = TypedJSONPatch[Untyped]
15+
type Patch = TypedPatch[Untyped]
1616

17-
type TypedJSONPatch[T any] struct {
17+
type TypedPatch[T any] struct {
1818
jpapi.JSONPatches
1919
}
2020

21-
type JSONPatchOptions struct {
21+
type Options struct {
2222
*jplib.ApplyOptions
2323

2424
// Indent is the string used for indentation in the output JSON.
2525
// Empty string means no indentation.
2626
Indent string
2727
}
2828

29-
type JSONPatchOption func(*JSONPatchOptions)
29+
type Option func(*Options)
3030

3131
// New creates a new JSONPatch with the given patches.
3232
// This JSONPatch's Apply method works on plain JSON bytes.
3333
// To apply the patches to an arbitrary type (which is marshalled to JSON before and unmarshalled back afterwards),
3434
// use NewTyped instead.
35-
func New(patches jpapi.JSONPatches) *JSONPatch {
36-
return &TypedJSONPatch[Untyped]{
35+
func New(patches jpapi.JSONPatches) *Patch {
36+
return &TypedPatch[Untyped]{
3737
JSONPatches: patches,
3838
}
3939
}
4040

4141
// NewTyped creates a new TypedJSONPatch with the given patches.
42-
func NewTyped[T any](patches jpapi.JSONPatches) *TypedJSONPatch[T] {
43-
return &TypedJSONPatch[T]{
42+
func NewTyped[T any](patches jpapi.JSONPatches) *TypedPatch[T] {
43+
return &TypedPatch[T]{
4444
JSONPatches: patches,
4545
}
4646
}
@@ -49,7 +49,7 @@ func NewTyped[T any](patches jpapi.JSONPatches) *TypedJSONPatch[T] {
4949
// If the generic type is Untyped (which is an alias for []byte),
5050
// it will treat the document as raw JSON bytes.
5151
// Otherwise, doc is marshalled to JSON before applying the patch and then again unmarshalled back to the original type afterwards.
52-
func (p *TypedJSONPatch[T]) Apply(doc T, options ...JSONPatchOption) (T, error) {
52+
func (p *TypedPatch[T]) Apply(doc T, options ...Option) (T, error) {
5353
var result T
5454
var rawDoc []byte
5555
isUntyped := reflect.TypeFor[T]() == reflect.TypeFor[Untyped]()
@@ -63,7 +63,7 @@ func (p *TypedJSONPatch[T]) Apply(doc T, options ...JSONPatchOption) (T, error)
6363
rawDoc = tmp
6464
}
6565

66-
opts := &JSONPatchOptions{
66+
opts := &Options{
6767
ApplyOptions: jplib.NewApplyOptions(),
6868
}
6969
for _, opt := range options {
@@ -100,57 +100,57 @@ func (p *TypedJSONPatch[T]) Apply(doc T, options ...JSONPatchOption) (T, error)
100100
// SupportNegativeIndices decides whether to support non-standard practice of
101101
// allowing negative indices to mean indices starting at the end of an array.
102102
// Default to true.
103-
func SupportNegativeIndices(val bool) JSONPatchOption {
104-
return func(opts *JSONPatchOptions) {
103+
func SupportNegativeIndices(val bool) Option {
104+
return func(opts *Options) {
105105
opts.SupportNegativeIndices = val
106106
}
107107
}
108108

109109
// AccumulatedCopySizeLimit limits the total size increase in bytes caused by
110110
// "copy" operations in a patch.
111-
func AccumulatedCopySizeLimit(val int64) JSONPatchOption {
112-
return func(opts *JSONPatchOptions) {
111+
func AccumulatedCopySizeLimit(val int64) Option {
112+
return func(opts *Options) {
113113
opts.AccumulatedCopySizeLimit = val
114114
}
115115
}
116116

117117
// AllowMissingPathOnRemove indicates whether to fail "remove" operations when the target path is missing.
118118
// Default to false.
119-
func AllowMissingPathOnRemove(val bool) JSONPatchOption {
120-
return func(opts *JSONPatchOptions) {
119+
func AllowMissingPathOnRemove(val bool) Option {
120+
return func(opts *Options) {
121121
opts.AllowMissingPathOnRemove = val
122122
}
123123
}
124124

125125
// EnsurePathExistsOnAdd instructs json-patch to recursively create the missing parts of path on "add" operation.
126126
// Defaults to false.
127-
func EnsurePathExistsOnAdd(val bool) JSONPatchOption {
128-
return func(opts *JSONPatchOptions) {
127+
func EnsurePathExistsOnAdd(val bool) Option {
128+
return func(opts *Options) {
129129
opts.EnsurePathExistsOnAdd = val
130130
}
131131
}
132132

133133
// EscapeHTML sets the EscapeHTML flag for json marshalling.
134134
// Defaults to true.
135-
func EscapeHTML(val bool) JSONPatchOption {
136-
return func(opts *JSONPatchOptions) {
135+
func EscapeHTML(val bool) Option {
136+
return func(opts *Options) {
137137
opts.EscapeHTML = val
138138
}
139139
}
140140

141141
// Indent sets the indentation string for the output JSON.
142142
// If empty, no indentation is applied.
143-
func Indent(val string) JSONPatchOption {
144-
return func(opts *JSONPatchOptions) {
143+
func Indent(val string) Option {
144+
return func(opts *Options) {
145145
opts.Indent = val
146146
}
147147
}
148148

149-
var _ json.Marshaler = &TypedJSONPatch[Untyped]{}
149+
var _ json.Marshaler = &TypedPatch[Untyped]{}
150150

151151
// MarshalJSON marshals the TypedJSONPatch to JSON.
152152
// Note that this uses the ConvertPath function to ensure that the paths are in the correct format.
153-
func (p *TypedJSONPatch[T]) MarshalJSON() ([]byte, error) {
153+
func (p *TypedPatch[T]) MarshalJSON() ([]byte, error) {
154154
if p == nil {
155155
return []byte("null"), nil
156156
}

0 commit comments

Comments
 (0)