@@ -53,8 +53,8 @@ type partialArray []*lazyNode
53
53
type container interface {
54
54
get (key string ) (* lazyNode , error )
55
55
set (key string , val * lazyNode ) error
56
- add (key string , val * lazyNode , supportNegativeIndices bool ) error
57
- remove (key string , allowMissingPathOnRemove bool , supportNegativeIndices bool ) error
56
+ add (key string , val * lazyNode , options * ApplyOptions ) error
57
+ remove (key string , options * ApplyOptions ) error
58
58
}
59
59
60
60
// ApplyOptions specifies options for calls to ApplyWithOptions.
@@ -410,7 +410,7 @@ func (d *partialDoc) set(key string, val *lazyNode) error {
410
410
return nil
411
411
}
412
412
413
- func (d * partialDoc ) add (key string , val * lazyNode , supportNegativeIndices bool ) error {
413
+ func (d * partialDoc ) add (key string , val * lazyNode , options * ApplyOptions ) error {
414
414
(* d )[key ] = val
415
415
return nil
416
416
}
@@ -423,10 +423,10 @@ func (d *partialDoc) get(key string) (*lazyNode, error) {
423
423
return v , nil
424
424
}
425
425
426
- func (d * partialDoc ) remove (key string , allowMissingPathOnRemove bool , supportNegativeIndices bool ) error {
426
+ func (d * partialDoc ) remove (key string , options * ApplyOptions ) error {
427
427
_ , ok := (* d )[key ]
428
428
if ! ok {
429
- if allowMissingPathOnRemove {
429
+ if options . AllowMissingPathOnRemove {
430
430
return nil
431
431
}
432
432
return errors .Wrapf (ErrMissing , "unable to remove nonexistent key: %s" , key )
@@ -447,7 +447,7 @@ func (d *partialArray) set(key string, val *lazyNode) error {
447
447
return nil
448
448
}
449
449
450
- func (d * partialArray ) add (key string , val * lazyNode , supportNegativeIndices bool ) error {
450
+ func (d * partialArray ) add (key string , val * lazyNode , options * ApplyOptions ) error {
451
451
if key == "-" {
452
452
* d = append (* d , val )
453
453
return nil
@@ -469,7 +469,7 @@ func (d *partialArray) add(key string, val *lazyNode, supportNegativeIndices boo
469
469
}
470
470
471
471
if idx < 0 {
472
- if ! supportNegativeIndices {
472
+ if ! options . SupportNegativeIndices {
473
473
return errors .Wrapf (ErrInvalidIndex , "Unable to access invalid index: %d" , idx )
474
474
}
475
475
if idx < - len (ary ) {
@@ -500,7 +500,7 @@ func (d *partialArray) get(key string) (*lazyNode, error) {
500
500
return (* d )[idx ], nil
501
501
}
502
502
503
- func (d * partialArray ) remove (key string , allowMissingPathOnRemove bool , supportNegativeIndices bool ) error {
503
+ func (d * partialArray ) remove (key string , options * ApplyOptions ) error {
504
504
idx , err := strconv .Atoi (key )
505
505
if err != nil {
506
506
return err
@@ -509,18 +509,18 @@ func (d *partialArray) remove(key string, allowMissingPathOnRemove bool, support
509
509
cur := * d
510
510
511
511
if idx >= len (cur ) {
512
- if allowMissingPathOnRemove {
512
+ if options . AllowMissingPathOnRemove {
513
513
return nil
514
514
}
515
515
return errors .Wrapf (ErrInvalidIndex , "Unable to access invalid index: %d" , idx )
516
516
}
517
517
518
518
if idx < 0 {
519
- if ! supportNegativeIndices {
519
+ if ! options . SupportNegativeIndices {
520
520
return errors .Wrapf (ErrInvalidIndex , "Unable to access invalid index: %d" , idx )
521
521
}
522
522
if idx < - len (cur ) {
523
- if allowMissingPathOnRemove {
523
+ if options . AllowMissingPathOnRemove {
524
524
return nil
525
525
}
526
526
return errors .Wrapf (ErrInvalidIndex , "Unable to access invalid index: %d" , idx )
@@ -537,7 +537,7 @@ func (d *partialArray) remove(key string, allowMissingPathOnRemove bool, support
537
537
return nil
538
538
}
539
539
540
- func (p Patch ) add (doc * container , op Operation , supportNegativeIndices bool ) error {
540
+ func (p Patch ) add (doc * container , op Operation , options * ApplyOptions ) error {
541
541
path , err := op .Path ()
542
542
if err != nil {
543
543
return errors .Wrapf (ErrMissing , "add operation failed to decode path" )
@@ -549,15 +549,15 @@ func (p Patch) add(doc *container, op Operation, supportNegativeIndices bool) er
549
549
return errors .Wrapf (ErrMissing , "add operation does not apply: doc is missing path: \" %s\" " , path )
550
550
}
551
551
552
- err = con .add (key , op .value (), supportNegativeIndices )
552
+ err = con .add (key , op .value (), options )
553
553
if err != nil {
554
554
return errors .Wrapf (err , "error in add for path: '%s'" , path )
555
555
}
556
556
557
557
return nil
558
558
}
559
559
560
- func (p Patch ) remove (doc * container , op Operation , allowMissingPathOnRemove bool , supportNegativeIndices bool ) error {
560
+ func (p Patch ) remove (doc * container , op Operation , options * ApplyOptions ) error {
561
561
path , err := op .Path ()
562
562
if err != nil {
563
563
return errors .Wrapf (ErrMissing , "remove operation failed to decode path" )
@@ -566,21 +566,21 @@ func (p Patch) remove(doc *container, op Operation, allowMissingPathOnRemove boo
566
566
con , key := findObject (doc , path )
567
567
568
568
if con == nil {
569
- if allowMissingPathOnRemove {
569
+ if options . AllowMissingPathOnRemove {
570
570
return nil
571
571
}
572
572
return errors .Wrapf (ErrMissing , "remove operation does not apply: doc is missing path: \" %s\" " , path )
573
573
}
574
574
575
- err = con .remove (key , allowMissingPathOnRemove , supportNegativeIndices )
575
+ err = con .remove (key , options )
576
576
if err != nil {
577
577
return errors .Wrapf (err , "error in remove for path: '%s'" , path )
578
578
}
579
579
580
580
return nil
581
581
}
582
582
583
- func (p Patch ) replace (doc * container , op Operation ) error {
583
+ func (p Patch ) replace (doc * container , op Operation , options * ApplyOptions ) error {
584
584
path , err := op .Path ()
585
585
if err != nil {
586
586
return errors .Wrapf (err , "replace operation failed to decode path" )
@@ -605,7 +605,7 @@ func (p Patch) replace(doc *container, op Operation) error {
605
605
return nil
606
606
}
607
607
608
- func (p Patch ) move (doc * container , op Operation , allowMissingPathOnRemove bool , supportNegativeIndices bool ) error {
608
+ func (p Patch ) move (doc * container , op Operation , options * ApplyOptions ) error {
609
609
from , err := op .From ()
610
610
if err != nil {
611
611
return errors .Wrapf (err , "move operation failed to decode from" )
@@ -622,7 +622,7 @@ func (p Patch) move(doc *container, op Operation, allowMissingPathOnRemove bool,
622
622
return errors .Wrapf (err , "error in move for path: '%s'" , key )
623
623
}
624
624
625
- err = con .remove (key , allowMissingPathOnRemove , supportNegativeIndices )
625
+ err = con .remove (key , options )
626
626
if err != nil {
627
627
return errors .Wrapf (err , "error in move for path: '%s'" , key )
628
628
}
@@ -638,15 +638,15 @@ func (p Patch) move(doc *container, op Operation, allowMissingPathOnRemove bool,
638
638
return errors .Wrapf (ErrMissing , "move operation does not apply: doc is missing destination path: %s" , path )
639
639
}
640
640
641
- err = con .add (key , val , supportNegativeIndices )
641
+ err = con .add (key , val , options )
642
642
if err != nil {
643
643
return errors .Wrapf (err , "error in move for path: '%s'" , path )
644
644
}
645
645
646
646
return nil
647
647
}
648
648
649
- func (p Patch ) test (doc * container , op Operation ) error {
649
+ func (p Patch ) test (doc * container , op Operation , options * ApplyOptions ) error {
650
650
path , err := op .Path ()
651
651
if err != nil {
652
652
return errors .Wrapf (err , "test operation failed to decode path" )
@@ -679,7 +679,7 @@ func (p Patch) test(doc *container, op Operation) error {
679
679
return errors .Wrapf (ErrTestFailed , "testing value %s failed" , path )
680
680
}
681
681
682
- func (p Patch ) copy (doc * container , op Operation , accumulatedCopySize * int64 , supportNegativeIndices bool , accumulatedCopySizeLimit int64 ) error {
682
+ func (p Patch ) copy (doc * container , op Operation , accumulatedCopySize * int64 , options * ApplyOptions ) error {
683
683
from , err := op .From ()
684
684
if err != nil {
685
685
return errors .Wrapf (err , "copy operation failed to decode from" )
@@ -713,11 +713,11 @@ func (p Patch) copy(doc *container, op Operation, accumulatedCopySize *int64, su
713
713
}
714
714
715
715
(* accumulatedCopySize ) += int64 (sz )
716
- if accumulatedCopySizeLimit > 0 && * accumulatedCopySize > accumulatedCopySizeLimit {
717
- return NewAccumulatedCopySizeError (accumulatedCopySizeLimit , * accumulatedCopySize )
716
+ if options . AccumulatedCopySizeLimit > 0 && * accumulatedCopySize > options . AccumulatedCopySizeLimit {
717
+ return NewAccumulatedCopySizeError (options . AccumulatedCopySizeLimit , * accumulatedCopySize )
718
718
}
719
719
720
- err = con .add (key , valCopy , supportNegativeIndices )
720
+ err = con .add (key , valCopy , options )
721
721
if err != nil {
722
722
return errors .Wrapf (err , "error while adding value during copy" )
723
723
}
@@ -792,17 +792,17 @@ func (p Patch) ApplyIndentWithOptions(doc []byte, indent string, options *ApplyO
792
792
for _ , op := range p {
793
793
switch op .Kind () {
794
794
case "add" :
795
- err = p .add (& pd , op , options . SupportNegativeIndices )
795
+ err = p .add (& pd , op , options )
796
796
case "remove" :
797
- err = p .remove (& pd , op , options . AllowMissingPathOnRemove , options . SupportNegativeIndices )
797
+ err = p .remove (& pd , op , options )
798
798
case "replace" :
799
- err = p .replace (& pd , op )
799
+ err = p .replace (& pd , op , options )
800
800
case "move" :
801
- err = p .move (& pd , op , options . AllowMissingPathOnRemove , options . SupportNegativeIndices )
801
+ err = p .move (& pd , op , options )
802
802
case "test" :
803
- err = p .test (& pd , op )
803
+ err = p .test (& pd , op , options )
804
804
case "copy" :
805
- err = p .copy (& pd , op , & accumulatedCopySize , options . SupportNegativeIndices , options . AccumulatedCopySizeLimit )
805
+ err = p .copy (& pd , op , & accumulatedCopySize , options )
806
806
default :
807
807
err = fmt .Errorf ("Unexpected kind: %s" , op .Kind ())
808
808
}
0 commit comments