* update patch workspacetemplate for supporting patch with JsonPatchType and change the authorization processing Signed-off-by: Wenhao Zhou <wenhaozhou@yunify.com> * make goimports * Fix: Of the type is not string will lead to panic Signed-off-by: Wenhao Zhou <wenhaozhou@yunify.com> * Add jsonpatchutil for handling json patch data Signed-off-by: Wenhao Zhou <wenhaozhou@yunify.com> * Updated patch workspacetemplate to to make the code run more efficiently * fix: multiple clusterrolebindings cannot autorizate * Correct wrong spelling Signed-off-by: Wenhao Zhou <wenhaozhou@yunify.com> Co-authored-by: Wenhao Zhou <wenhaozhou@yunify.com>
23 lines
450 B
Go
23 lines
450 B
Go
package josnpatchutil
|
|
|
|
import (
|
|
jsonpatch "github.com/evanphx/json-patch"
|
|
"github.com/mitchellh/mapstructure"
|
|
)
|
|
|
|
func Parse(raw []byte) (jsonpatch.Patch, error) {
|
|
return jsonpatch.DecodePatch(raw)
|
|
}
|
|
|
|
func GetValue(patch jsonpatch.Operation, value interface{}) error {
|
|
valueInterface, err := patch.ValueInterface()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := mapstructure.Decode(valueInterface, value); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|