瀏覽代碼

udpate vendor

lijian 2 年之前
父節點
當前提交
53fbc9e6c5

+ 21 - 0
vendor/github.com/apapsch/go-jsonmerge/LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2016-2019 Artur Kraev
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 81 - 0
vendor/github.com/apapsch/go-jsonmerge/README.md

@@ -0,0 +1,81 @@
+# go-jsonmerge
+[![Build Status](https://travis-ci.org/RaveNoX/go-jsonmerge.svg?branch=master)](https://travis-ci.org/RaveNoX/go-jsonmerge)
+[![GoDoc](https://godoc.org/github.com/RaveNoX/go-jsonmerge?status.svg)](https://godoc.org/github.com/RaveNoX/go-jsonmerge)
+
+GO library for merging JSON objects
+
+## Original document
+```json
+{  
+  "number": 1,
+  "string": "value",
+  "object": {
+    "number": 1,
+    "string": "value",
+    "nested object": {
+      "number": 2
+    },
+    "array": [1, 2, 3],
+    "partial_array": [1, 2, 3]
+  }
+}
+```
+
+## Patch
+```json
+{  
+  "number": 2,
+  "string": "value1",
+  "nonexitent": "woot",
+  "object": {
+    "number": 3,
+    "string": "value2",
+    "nested object": {
+      "number": 4
+    },
+    "array": [3, 2, 1],
+    "partial_array": {
+      "1": 4
+    }
+  }
+}
+```
+
+## Result
+```json
+{  
+  "number": 2,
+  "string": "value1",
+  "object": {
+    "number": 3,
+    "string": "value2",
+    "nested object": {
+      "number": 4
+    },
+    "array": [3, 2, 1],
+    "partial_array": [1, 4, 3]
+  }
+}
+```
+
+## Commandline Tool
+
+```bash
+$ go get -u github.com/RaveNoX/go-jsonmerge/cmd/jsonmerge
+$ jsonmerge [options] <patch.json> <glob1.json> <glob2.json>...<globN.json>
+# For help
+$ jsonmerge -h
+```
+
+## Development
+```
+# Install depencencies
+./init.sh
+
+# Build
+./build.sh
+```
+
+
+## License
+[MIT](./LICENSE.MD)

+ 25 - 0
vendor/github.com/apapsch/go-jsonmerge/build.cmd

@@ -0,0 +1,25 @@
+@ECHO OFF
+setlocal
+
+set GOARCH=amd64
+
+cd %~dp0
+md artifacts
+
+echo Windows
+set GOOS=windows
+call go build -o artifacts\jsonmerge.exe .\cmd || goto :error
+
+echo Linux
+set GOOS=linux
+call go build -o artifacts\jsonmerge .\cmd || goto :error
+
+echo Darwin
+set GOOS=darwin
+call go build -o artifacts\jsonmerge_darwin .\cmd || goto :error
+
+echo Build done
+exit
+
+:error
+exit /b %errorlevel%

+ 19 - 0
vendor/github.com/apapsch/go-jsonmerge/build.sh

@@ -0,0 +1,19 @@
+#!/bin/sh
+
+set -e
+
+MY_DIR=$(dirname "$0")
+
+cd "${MY_DIR}"
+mkdir -p "artifacts"
+
+echo "Linux"
+GOARCH=amd64 GOOS=linux go build -o "artifacts/jsonmerge" ./cmd
+
+echo "Windows"
+GOARCH=amd64 GOOS=windows go build -o "artifacts/jsonmerge.exe" ./cmd
+
+echo "Mac(darwin)"
+GOARCH=amd64 GOOS=darwin go build -o "artifacts/jsonmerge_darwin" ./cmd
+
+echo "Build done"

+ 52 - 0
vendor/github.com/apapsch/go-jsonmerge/doc.go

@@ -0,0 +1,52 @@
+// Package jsonmerge helps mergeing JSON objects
+//
+// For example you have this documents:
+//
+// original.json
+//  {
+//    "number": 1,
+//    "string": "value",
+//    "object": {
+//      "number": 1,
+//        "string": "value",
+//        "nested object": {
+//          "number": 2
+//        },
+//        "array": [1, 2, 3],
+//        "partial_array": [1, 2, 3]
+//     }
+//  }
+//
+// patch.json
+//  {
+//    "number": 2,
+//    "string": "value1",
+//    "nonexitent": "woot",
+//    "object": {
+//      "number": 3,
+//      "string": "value2",
+//      "nested object": {
+//        "number": 4
+//      },
+//      "array": [3, 2, 1],
+//      "partial_array": {
+//        "1": 4
+//      }
+//    }
+//  }
+//
+// After merge you will have this result:
+//  {
+//    "number": 2,
+//    "string": "value1",
+//    "object": {
+//      "number": 3,
+//      "string": "value2",
+//      "nested object": {
+//        "number": 4
+//      },
+//      "array": [3, 2, 1],
+//      "partial_array": [1, 4, 3]
+//    }
+//  }
+package jsonmerge

+ 11 - 0
vendor/github.com/apapsch/go-jsonmerge/go.mod

@@ -0,0 +1,11 @@
+module github.com/apapsch/go-jsonmerge/v2
+
+go 1.12
+
+require (
+	github.com/RaveNoX/go-jsoncommentstrip v1.0.0
+	github.com/bmatcuk/doublestar v1.1.1
+	github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d
+	github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad
+	github.com/stretchr/testify v1.3.0 // indirect
+)

+ 15 - 0
vendor/github.com/apapsch/go-jsonmerge/go.sum

@@ -0,0 +1,15 @@
+github.com/RaveNoX/go-jsoncommentstrip v1.0.0 h1:t527LHHE3HmiHrq74QMpNPZpGCIJzTx+apLkMKt4HC0=
+github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
+github.com/bmatcuk/doublestar v1.1.1 h1:YroD6BJCZBYx06yYFEWvUuKVWQn3vLLQAVmDmvTSaiQ=
+github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d h1:c93kUJDtVAXFEhsCh5jSxyOJmFHuzcihnslQiX8Urwo=
+github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad h1:fiWzISvDn0Csy5H0iwgAuJGQTUpVfEMJJd4nRFXogbc=
+github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=

+ 167 - 0
vendor/github.com/apapsch/go-jsonmerge/merge.go

@@ -0,0 +1,167 @@
+package jsonmerge
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"reflect"
+	"strconv"
+	"strings"
+)
+
+// Merger describes result of merge operation and provides
+// configuration.
+type Merger struct {
+	// Errors is slice of non-critical errors of merge operations
+	Errors []error
+	// Replaced is describe replacements
+	// Key is path in document like
+	//   "prop1.prop2.prop3" for object properties or
+	//   "arr1.1.prop" for arrays
+	// Value is value of replacemet
+	Replaced map[string]interface{}
+	// CopyNonexistent enables setting fields into the result
+	// which only exist in the patch.
+	CopyNonexistent bool
+}
+
+func (m *Merger) mergeValue(path []string, patch map[string]interface{}, key string, value interface{}) interface{} {
+	patchValue, patchHasValue := patch[key]
+
+	if !patchHasValue {
+		return value
+	}
+
+	_, patchValueIsObject := patchValue.(map[string]interface{})
+
+	path = append(path, key)
+	pathStr := strings.Join(path, ".")
+
+	if _, ok := value.(map[string]interface{}); ok {
+		if !patchValueIsObject {
+			err := fmt.Errorf("patch value must be object for key \"%v\"", pathStr)
+			m.Errors = append(m.Errors, err)
+			return value
+		}
+
+		return m.mergeObjects(value, patchValue, path)
+	}
+
+	if _, ok := value.([]interface{}); ok && patchValueIsObject {
+		return m.mergeObjects(value, patchValue, path)
+	}
+
+	if !reflect.DeepEqual(value, patchValue) {
+		m.Replaced[pathStr] = patchValue
+	}
+
+	return patchValue
+}
+
+func (m *Merger) mergeObjects(data, patch interface{}, path []string) interface{} {
+	if patchObject, ok := patch.(map[string]interface{}); ok {
+		if dataArray, ok := data.([]interface{}); ok {
+			ret := make([]interface{}, len(dataArray))
+
+			for i, val := range dataArray {
+				ret[i] = m.mergeValue(path, patchObject, strconv.Itoa(i), val)
+			}
+
+			return ret
+		} else if dataObject, ok := data.(map[string]interface{}); ok {
+			ret := make(map[string]interface{})
+
+			for k, v := range dataObject {
+				ret[k] = m.mergeValue(path, patchObject, k, v)
+			}
+			if m.CopyNonexistent {
+				for k, v := range patchObject {
+					if _, ok := dataObject[k]; !ok {
+						ret[k] = v
+					}
+				}
+			}
+
+			return ret
+		}
+	}
+
+	return data
+}
+
+// Merge merges patch document to data document
+//
+// Returning merged document. Result of merge operation can be
+// obtained from the Merger. Result information is discarded before
+// merging.
+func (m *Merger) Merge(data, patch interface{}) interface{} {
+	m.Replaced = make(map[string]interface{})
+	m.Errors = make([]error, 0)
+	return m.mergeObjects(data, patch, nil)
+}
+
+// MergeBytesIndent merges patch document buffer to data document buffer
+//
+// Use prefix and indent for set indentation like in json.MarshalIndent
+//
+// Returning merged document buffer and error if any.
+func (m *Merger) MergeBytesIndent(dataBuff, patchBuff []byte, prefix, indent string) (mergedBuff []byte, err error) {
+	var data, patch, merged interface{}
+
+	err = unmarshalJSON(dataBuff, &data)
+	if err != nil {
+		err = fmt.Errorf("error in data JSON: %v", err)
+		return
+	}
+
+	err = unmarshalJSON(patchBuff, &patch)
+	if err != nil {
+		err = fmt.Errorf("error in patch JSON: %v", err)
+		return
+	}
+
+	merged = m.Merge(data, patch)
+
+	mergedBuff, err = json.MarshalIndent(merged, prefix, indent)
+	if err != nil {
+		err = fmt.Errorf("error writing merged JSON: %v", err)
+	}
+
+	return
+}
+
+// MergeBytes merges patch document buffer to data document buffer
+//
+// Returning merged document buffer, merge info and
+// error if any
+func (m *Merger) MergeBytes(dataBuff, patchBuff []byte) (mergedBuff []byte, err error) {
+	var data, patch, merged interface{}
+
+	err = unmarshalJSON(dataBuff, &data)
+	if err != nil {
+		err = fmt.Errorf("error in data JSON: %v", err)
+		return
+	}
+
+	err = unmarshalJSON(patchBuff, &patch)
+	if err != nil {
+		err = fmt.Errorf("error in patch JSON: %v", err)
+		return
+	}
+
+	merged = m.Merge(data, patch)
+
+	mergedBuff, err = json.Marshal(merged)
+	if err != nil {
+		err = fmt.Errorf("error writing merged JSON: %v", err)
+	}
+
+	return
+}
+
+func unmarshalJSON(buff []byte, data interface{}) error {
+	decoder := json.NewDecoder(bytes.NewReader(buff))
+	decoder.UseNumber()
+
+	return decoder.Decode(data)
+}

+ 12 - 0
vendor/vendor.json

@@ -46,6 +46,18 @@
 			"revision": "ebe99fcebbcedf6e7916320cce24c3e1832766ac",
 			"revisionTime": "2018-03-14T04:19:18Z"
 		},
+		{
+			"checksumSHA1": "CSzyeI5CgbidMD+LrmyPoJZ9dYc=",
+			"path": "github.com/apapsch/go-jsonmerge",
+			"revision": "90b01458c2af82553f17c56a431386c57a8a569f",
+			"revisionTime": "2021-11-19T17:29:21Z",
+			"version": "v2.0.0",
+			"versionExact": "v2.0.0"
+		},
+		{
+			"path": "github.com/apapsch/go-jsonmerge/v2",
+			"revision": ""
+		},
 		{
 			"checksumSHA1": "VBJvl7hE2PhuuUgCz5CqEA9Xb1g=",
 			"origin": "github.com/kataras/iris/vendor/github.com/aymerick/raymond",