summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/bennyscetbun
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/bennyscetbun')
-rw-r--r--vendor/github.com/bennyscetbun/jsongo/.gitignore24
-rw-r--r--vendor/github.com/bennyscetbun/jsongo/LICENSE21
-rw-r--r--vendor/github.com/bennyscetbun/jsongo/README.md574
-rw-r--r--vendor/github.com/bennyscetbun/jsongo/debug.go60
-rw-r--r--vendor/github.com/bennyscetbun/jsongo/jsongo.go472
-rw-r--r--vendor/github.com/bennyscetbun/jsongo/print.go74
6 files changed, 0 insertions, 1225 deletions
diff --git a/vendor/github.com/bennyscetbun/jsongo/.gitignore b/vendor/github.com/bennyscetbun/jsongo/.gitignore
deleted file mode 100644
index 32678c7..0000000
--- a/vendor/github.com/bennyscetbun/jsongo/.gitignore
+++ /dev/null
@@ -1,24 +0,0 @@
-# Compiled Object files, Static and Dynamic libs (Shared Objects)
-*.o
-*.a
-*.so
-
-# Folders
-_obj
-_test
-
-# Architecture specific extensions/prefixes
-*.[568vq]
-[568vq].out
-
-*.cgo1.go
-*.cgo2.c
-_cgo_defun.c
-_cgo_gotypes.go
-_cgo_export.*
-
-_testmain.go
-
-*.exe
-*.test
-*~
diff --git a/vendor/github.com/bennyscetbun/jsongo/LICENSE b/vendor/github.com/bennyscetbun/jsongo/LICENSE
deleted file mode 100644
index aab88ef..0000000
--- a/vendor/github.com/bennyscetbun/jsongo/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2014 Benny Scetbun
-
-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.
diff --git a/vendor/github.com/bennyscetbun/jsongo/README.md b/vendor/github.com/bennyscetbun/jsongo/README.md
deleted file mode 100644
index ebc81c6..0000000
--- a/vendor/github.com/bennyscetbun/jsongo/README.md
+++ /dev/null
@@ -1,574 +0,0 @@
-jsongo
-======
-
-**Jsongo is a simple library for golang to help you build Json without static struct or map[string]interface**
-
-[json.Marshal](http://golang.org/pkg/encoding/json/#Marshal) and [json.Unmarshal](http://golang.org/pkg/encoding/json/#Unmarshal) have never been that easy
-
-**If you had only one function to look at, look at the "[At](#at)" function**
-
-***If you want an easy way to turn your json into a structure you should use the "[Print](#print)" function after unmarshalling json in a JSONNODE***
-
-You can find the doc on godoc.org [![GoDoc](https://godoc.org/github.com/bennyscetbun/jsongo?status.png)](https://godoc.org/github.com/bennyscetbun/jsongo)
-
-
-##JsonNode
-
-JsonNode is the basic Structure that you must use when using jsongo. It can either be a:
-- Map (jsongo.TypeMap)
-- Array (jsongo.TypeArray)
-- Value (jsongo.TypeValue) *Precisely a pointer store in an interface{}*
-- Undefined (jsongo.TypeUndefined) *default type*
-
-*When a JSONNode Type is set you cant change it without using Unset() first*
-____
-###Val
-####Synopsis:
-turn this JSONNode to TypeValue and set that value
-```go
-func (that *JSONNode) Val(val interface{})
-```
-
-####Examples
-#####code:
-```go
-package main
-
-import (
- "github.com/bennyscetbun/jsongo"
-)
-
-func main() {
- root := jsongo.JSONNode{}
- root.Val(42)
- root.DebugPrint("")
-}
-```
-#####output:
-```
-42
-```
-#####code:
-```go
-package main
-
-import (
- "github.com/bennyscetbun/jsongo"
-)
-type MyStruct struct {
- Member1 string
- Member2 int
-}
-
-func main() {
- root := jsongo.JSONNode{}
- root.Val(MyStruct{"The answer", 42})
- root.DebugPrint("")
-}
-```
-#####output:
-```
-{
- "Member1": "The answer",
- "Member2": 42
-}
-```
-_____
-###Array
-####Synopsis:
- Turn this JSONNode to a TypeArray and/or set the array size (reducing size will make you loose data)
-```go
-func (that *JSONNode) Array(size int) *[]JSONNode
-```
-
-####Examples
-#####code:
-```go
-package main
-
-import (
- "github.com/bennyscetbun/jsongo"
-)
-
-func main() {
- root := jsongo.JSONNode{}
- a := root.Array(4)
- for i := 0; i < 4; i++ {
- (*a)[i].Val(i)
- }
- root.DebugPrint("")
-}
-```
-#####output:
-```
-[
- 0,
- 1,
- 2,
- 3
-]
-```
-#####code:
-```go
-package main
-
-import (
- "github.com/bennyscetbun/jsongo"
-)
-
-func main() {
- root := jsongo.JSONNode{}
- a := root.Array(4)
- for i := 0; i < 4; i++ {
- (*a)[i].Val(i)
- }
- root.Array(2) //Here we reduce the size and we loose some data
- root.DebugPrint("")
-}
-```
-#####output:
-```
-[
- 0,
- 1
-]
-```
-____
-###Map
-####Synopsis:
-Turn this JSONNode to a TypeMap and/or Create a new element for key if necessary and return it
-```go
-func (that *JSONNode) Map(key string) *JSONNode
-```
-
-####Examples
-#####code:
-```go
-package main
-
-import (
- "github.com/bennyscetbun/jsongo"
-)
-
-func main() {
- root := jsongo.JSONNode{}
- root.Map("there").Val("you are")
- root.Map("here").Val("you should be")
- root.DebugPrint("")
-}
-```
-#####output:
-```
-{
- "here": "you should be",
- "there": "you are"
-}
-```
-____
-###At
-####Synopsis:
-Helps you move through your node by building them on the fly
-
-*val can be string or int only*
-
-*strings are keys for TypeMap*
-
-*ints are index in TypeArray (it will make array grow on the fly, so you should start to populate with the biggest index first)*
-```go
-func (that *JSONNode) At(val ...interface{}) *JSONNode
-```
-
-####Examples
-#####code:
-```go
-package main
-
-import (
- "github.com/bennyscetbun/jsongo"
-)
-
-func main() {
- root := jsongo.JSONNode{}
- root.At(4, "Who").Val("Let the dog out") //is equivalent to (*root.Array(5))[4].Map("Who").Val("Let the dog out")
- root.DebugPrint("")
-}
-```
-#####output:
-```
-[
- null,
- null,
- null,
- null,
- {
- "Who": "Let the dog out"
- }
-]
-```
-#####code:
-```go
-package main
-
-import (
- "github.com/bennyscetbun/jsongo"
-)
-
-func main() {
- root := jsongo.JSONNode{}
- root.At(4, "Who").Val("Let the dog out")
- //to win some time you can even even save a certain JSONNode
- node := root.At(2, "What")
- node.At("Can", "You").Val("do with that?")
- node.At("Do", "You", "Think").Val("Of that")
- root.DebugPrint("")
-}
-```
-#####output:
-```
-[
- null,
- null,
- {
- "What": {
- "Can": {
- "You": "do with that?"
- },
- "Do": {
- "You": {
- "Think": "Of that"
- }
- }
- }
- },
- null,
- {
- "Who": "Let the dog out"
- }
-]
-```
-____
-###Print
-####Synopsis:
-Helps you build your code by printing a go structure from the json you ve just unmarshaled
-
-```go
-func (that *JSONNode) Print()
-```
-
-____
-###Other Function
-There is plenty of other function, you should check the complete doc [![GoDoc](https://godoc.org/github.com/bennyscetbun/jsongo?status.png)](https://godoc.org/github.com/bennyscetbun/jsongo)
-
-####A last Example for fun
-#####code:
-```go
-package main
-
-import (
- "github.com/bennyscetbun/jsongo"
-)
-
-func ShowOnlyValue(current *jsongo.JSONNode) {
- switch current.GetType() {
- case jsongo.TypeValue:
- println(current.Get().(string))
- case jsongo.TypeMap:
- for _, key := range current.GetKeys() {
- ShowOnlyValue(current.At(key))
- }
- case jsongo.TypeArray:
- for _, key := range current.GetKeys() {
- ShowOnlyValue(current.At(key))
- }
- }
-}
-
-func main() {
- root := jsongo.JSONNode{}
- root.At(4, "Who").Val("Let the dog out")
- node := root.At(2, "What")
- node.At("Can", "You").Val("do with that?")
- node.At("Do", "You", "Think").Val("Of that")
- ShowOnlyValue(&root)
-}
-```
-#####output:
-```
-Of that
-do with that?
-Let the dog out
-```
-_____
-_____
-##Json Marshal/Unmarshal
-
-One of the main purpose of jsongo was to create Json from data without using static structure or map[string]interface.
-
-You can use the full power of the [encoding/json](http://golang.org/pkg/encoding/json/) package with jsongo.
-
-###Marshal
-####Example
-#####code:
-```go
-package main
-
-import (
- "encoding/json"
- "fmt"
- "github.com/bennyscetbun/jsongo"
-)
-
-type Test struct {
- Static string `json:"static"`
- Over int `json:"over"`
-}
-
-func main() {
- root := jsongo.JSONNode{}
- root.At("A", "AA", "AAA").Val(42)
-
- node := root.At("A", "AB")
- node.At(1).Val("Peace")
- node.At(0).Val(Test{"struct suck when you build json", 9000})
- root.At("B").Val("Oh Yeah")
-
- tojson, err := json.MarshalIndent(&root, "", " ")
- if err != nil {
- fmt.Printf("%s\n", err.Error())
- return
- }
- fmt.Printf("%s\n", tojson)
-}
-```
-#####output:
-```
-{
- "A": {
- "AA": {
- "AAA": 42
- },
- "AB": [
- {
- "static": "struct suck when you build json",
- "over": 9000
- },
- "Peace"
- ]
- },
- "B": "Oh Yeah"
-}
-```
-____
-###Unmarshal
-Unmarshal using JSONNode follow some simple rules:
-- Any TypeUndefined JSONNode will be set to the right type, any other type wont be changed
-- Array will grow if necessary
-- New keys will be added to Map
-- Values set to nil "*.Val(nil)*" will be turn into the type decide by Json
-- It will respect any current mapping and will return errors if needed
-
-You can set a node as "DontExpand" with the UnmarshalDontExpand function and thoose rules will apply:
-- The type wont be change for any type
-- Array wont grow
-- New keys wont be added to Map
-- Values set to nil "*.Val(nil)*" will be turn into the type decide by Json
-- It will respect any current mapping and will return errors if needed
-
-####Example of full expand
-#####code:
-```go
-package main
-
-import (
- "encoding/json"
- "github.com/bennyscetbun/jsongo"
- "fmt"
-)
-
-func main() {
- root := jsongo.JSONNode{}
- fromjson := `{
- "A": {
- "AA": {
- "AAA": 42
- },
- "AB": [
- {
- "static": "struct suck when you build json",
- "over": 9000
- },
- "Peace"
- ]
- },
- "B": "Oh Yeah"
- }`
- err := json.Unmarshal([]byte(fromjson), &root)
- if err != nil {
- fmt.Printf("%s\n", err.Error())
- return
- }
- root.DebugProspect(0, "\t")
-}
-```
-#####output:
-```
-Is of Type: TypeMap
-A:
- Is of Type: TypeMap
- AA:
- Is of Type: TypeMap
- AAA:
- Is of Type: TypeValue
- Value of type: float64
- 42
- AB:
- Is of Type: TypeArray
- [0]:
- Is of Type: TypeMap
- static:
- Is of Type: TypeValue
- Value of type: string
- struct suck when you build json
- over:
- Is of Type: TypeValue
- Value of type: float64
- 9000
- [1]:
- Is of Type: TypeValue
- Value of type: string
- Peace
-B:
- Is of Type: TypeValue
- Value of type: string
- Oh Yeah
-```
-####Example expand with mapping
-#####code:
-```go
-package main
-
-import (
- "encoding/json"
- "github.com/bennyscetbun/jsongo"
- "fmt"
-)
-type Test struct {
- Static string `json:"static"`
- Over int `json:"over"`
-}
-
-func main() {
- root := jsongo.JSONNode{}
- fromjson := `{
- "A": {
- "AA": {
- "AAA": 42
- },
- "AB": [
- {
- "static": "struct suck when you build json",
- "over": 9000
- },
- "Peace"
- ]
- },
- "B": "Oh Yeah"
- }`
- root.At("A", "AB", 0).Val(Test{})
- err := json.Unmarshal([]byte(fromjson), &root)
- if err != nil {
- fmt.Printf("%s\n", err.Error())
- return
- }
- root.DebugProspect(0, "\t")
-}
-```
-#####output:
-```
-Is of Type: TypeMap
-A:
- Is of Type: TypeMap
- AB:
- Is of Type: TypeArray
- [0]:
- Is of Type: TypeValue
- Value of type: main.Test
- {Static:struct suck when you build json Over:9000}
- [1]:
- Is of Type: TypeValue
- Value of type: string
- Peace
- AA:
- Is of Type: TypeMap
- AAA:
- Is of Type: TypeValue
- Value of type: float64
- 42
-B:
- Is of Type: TypeValue
- Value of type: string
- Oh Yeah
-```
-####Example expand with some UnmarshalDontExpand
-#####code:
-```go
-package main
-
-import (
- "encoding/json"
- "github.com/bennyscetbun/jsongo"
- "fmt"
-)
-type Test struct {
- Static string `json:"static"`
- Over int `json:"over"`
-}
-
-func main() {
- root := jsongo.JSONNode{}
- fromjson := `{
- "A": {
- "AA": {
- "AAA": 42
- },
- "AB": [
- {
- "static": "struct suck when you build json",
- "over": 9000
- },
- "Peace"
- ]
- },
- "B": "Oh Yeah"
- }`
- root.At("A", "AB").UnmarshalDontExpand(true, false).At(0).Val(Test{})
- err := json.Unmarshal([]byte(fromjson), &root)
- if err != nil {
- fmt.Printf("%s\n", err.Error())
- return
- }
- root.DebugProspect(0, "\t")
-}
-```
-#####output:
-```
-Is of Type: TypeMap
-A:
- Is of Type: TypeMap
- AB:
- Is of Type: TypeArray
- [0]:
- Is of Type: TypeValue
- Value of type: main.Test
- {Static:struct suck when you build json Over:9000}
- AA:
- Is of Type: TypeMap
- AAA:
- Is of Type: TypeValue
- Value of type: float64
- 42
-B:
- Is of Type: TypeValue
- Value of type: string
- Oh Yeah
-```
diff --git a/vendor/github.com/bennyscetbun/jsongo/debug.go b/vendor/github.com/bennyscetbun/jsongo/debug.go
deleted file mode 100644
index a1aa425..0000000
--- a/vendor/github.com/bennyscetbun/jsongo/debug.go
+++ /dev/null
@@ -1,60 +0,0 @@
-package jsongo
-
-import (
- "encoding/json"
- "fmt"
- "os"
-)
-
-//DebugPrint Print a JSONNode as json withindent
-func (that *JSONNode) DebugPrint(prefix string) {
- asJSON, err := json.MarshalIndent(that, "", " ")
- if err != nil {
- fmt.Printf("%s\n", err.Error())
- os.Exit(-1)
- }
- fmt.Printf("%s%s\n", prefix, asJSON)
-}
-
-func printfindent(indentlevel int, indentchar string, format string, args ...interface{}) {
- for i := 0; i < indentlevel; i++ {
- fmt.Printf("%s", indentchar)
- }
- fmt.Printf(format, args...)
-}
-
-func (that *JSONNode) debugProspectValue(indentlevel int, indentchar string) {
- printfindent(indentlevel, indentchar, "Is of Type: TypeValue\n")
- printfindent(indentlevel, indentchar, "Value of type: %T\n", that.Get())
- printfindent(indentlevel, indentchar, "%+v\n", that.Get())
-}
-
-func (that *JSONNode) debugProspectMap(indentlevel int, indentchar string) {
- printfindent(indentlevel, indentchar, "Is of Type: TypeMap\n")
- for key := range that.m {
- printfindent(indentlevel, indentchar, "%s:\n", key)
- that.m[key].DebugProspect(indentlevel+1, indentchar)
- }
-}
-
-func (that *JSONNode) debugProspectArray(indentlevel int, indentchar string) {
- printfindent(indentlevel, indentchar, "Is of Type: TypeArray\n")
- for key := range that.a {
- printfindent(indentlevel, indentchar, "[%d]:\n", key)
- that.a[key].DebugProspect(indentlevel+1, indentchar)
- }
-}
-
-//DebugProspect Print all the data the we ve got on a node and all it s children
-func (that *JSONNode) DebugProspect(indentlevel int, indentchar string) {
- switch that.t {
- case TypeValue:
- that.debugProspectValue(indentlevel, indentchar)
- case TypeMap:
- that.debugProspectMap(indentlevel, indentchar)
- case TypeArray:
- that.debugProspectArray(indentlevel, indentchar)
- case TypeUndefined:
- printfindent(indentlevel, indentchar, "Is of Type: TypeUndefined\n")
- }
-}
diff --git a/vendor/github.com/bennyscetbun/jsongo/jsongo.go b/vendor/github.com/bennyscetbun/jsongo/jsongo.go
deleted file mode 100644
index d661931..0000000
--- a/vendor/github.com/bennyscetbun/jsongo/jsongo.go
+++ /dev/null
@@ -1,472 +0,0 @@
-// Copyright 2014 Benny Scetbun. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-// Package Jsongo is a simple library to help you build Json without static struct
-//
-// Source code and project home:
-// https://github.com/benny-deluxe/jsongo
-//
-
-package jsongo
-
-import (
- "encoding/json"
- "errors"
- "reflect"
- //"fmt"
-)
-
-//ErrorKeyAlreadyExist error if a key already exist in current JSONNode
-var ErrorKeyAlreadyExist = errors.New("jsongo key already exist")
-
-//ErrorMultipleType error if a JSONNode already got a different type of value
-var ErrorMultipleType = errors.New("jsongo this node is already set to a different jsonNodeType")
-
-//ErrorArrayNegativeValue error if you ask for a negative index in an array
-var ErrorArrayNegativeValue = errors.New("jsongo negative index for array")
-
-//ErrorArrayNegativeValue error if you ask for a negative index in an array
-var ErrorAtUnsupportedType = errors.New("jsongo Unsupported Type as At argument")
-
-//ErrorRetrieveUserValue error if you ask the value of a node that is not a value node
-var ErrorRetrieveUserValue = errors.New("jsongo Cannot retrieve node's value which is not of type value")
-
-//ErrorTypeUnmarshaling error if you try to unmarshal something in the wrong type
-var ErrorTypeUnmarshaling = errors.New("jsongo Wrong type when Unmarshaling")
-
-//ErrorUnknowType error if you try to use an unknow JSONNodeType
-var ErrorUnknowType = errors.New("jsongo Unknow JSONNodeType")
-
-//ErrorValNotPointer error if you try to use Val without a valid pointer
-var ErrorValNotPointer = errors.New("jsongo: Val: arguments must be a pointer and not nil")
-
-//ErrorGetKeys error if you try to get the keys from a JSONNode that isnt a TypeMap or a TypeArray
-var ErrorGetKeys = errors.New("jsongo: GetKeys: JSONNode is not a TypeMap or TypeArray")
-
-//ErrorDeleteKey error if you try to call DelKey on a JSONNode that isnt a TypeMap
-var ErrorDeleteKey = errors.New("jsongo: DelKey: This JSONNode is not a TypeMap")
-
-//ErrorCopyType error if you try to call Copy on a JSONNode that isnt a TypeUndefined
-var ErrorCopyType = errors.New("jsongo: Copy: This JSONNode is not a TypeUndefined")
-
-//JSONNode Datastructure to build and maintain Nodes
-type JSONNode struct {
- m map[string]*JSONNode
- a []JSONNode
- v interface{}
- vChanged bool //True if we changed the type of the value
- t JSONNodeType //Type of that JSONNode 0: Not defined, 1: map, 2: array, 3: value
- dontExpand bool //dont expand while Unmarshal
-}
-
-//JSONNodeType is used to set, check and get the inner type of a JSONNode
-type JSONNodeType uint
-
-const (
- //TypeUndefined is set by default for empty JSONNode
- TypeUndefined JSONNodeType = iota
- //TypeMap is set when a JSONNode is a Map
- TypeMap
- //TypeArray is set when a JSONNode is an Array
- TypeArray
- //TypeValue is set when a JSONNode is a Value Node
- TypeValue
- //typeError help us detect errors
- typeError
-)
-
-//At helps you move through your node by building them on the fly
-//
-//val can be string or int only
-//
-//strings are keys for TypeMap
-//
-//ints are index in TypeArray (it will make array grow on the fly, so you should start to populate with the biggest index first)*
-func (that *JSONNode) At(val ...interface{}) *JSONNode {
- if len(val) == 0 {
- return that
- }
- switch vv := val[0].(type) {
- case string:
- return that.atMap(vv, val[1:]...)
- case int:
- return that.atArray(vv, val[1:]...)
- }
- panic(ErrorAtUnsupportedType)
-}
-
-//atMap return the JSONNode in current map
-func (that *JSONNode) atMap(key string, val ...interface{}) *JSONNode {
- if that.t != TypeUndefined && that.t != TypeMap {
- panic(ErrorMultipleType)
- }
- if that.m == nil {
- that.m = make(map[string]*JSONNode)
- that.t = TypeMap
- }
- if next, ok := that.m[key]; ok {
- return next.At(val...)
- }
- that.m[key] = new(JSONNode)
- return that.m[key].At(val...)
-}
-
-//atArray return the JSONNode in current TypeArray (and make it grow if necessary)
-func (that *JSONNode) atArray(key int, val ...interface{}) *JSONNode {
- if that.t == TypeUndefined {
- that.t = TypeArray
- } else if that.t != TypeArray {
- panic(ErrorMultipleType)
- }
- if key < 0 {
- panic(ErrorArrayNegativeValue)
- }
- if key >= len(that.a) {
- newa := make([]JSONNode, key+1)
- for i := 0; i < len(that.a); i++ {
- newa[i] = that.a[i]
- }
- that.a = newa
- }
- return that.a[key].At(val...)
-}
-
-//Map Turn this JSONNode to a TypeMap and/or Create a new element for key if necessary and return it
-func (that *JSONNode) Map(key string) *JSONNode {
- if that.t != TypeUndefined && that.t != TypeMap {
- panic(ErrorMultipleType)
- }
- if that.m == nil {
- that.m = make(map[string]*JSONNode)
- that.t = TypeMap
- }
- if _, ok := that.m[key]; ok {
- return that.m[key]
- }
- that.m[key] = &JSONNode{}
- return that.m[key]
-}
-
-//Array Turn this JSONNode to a TypeArray and/or set the array size (reducing size will make you loose data)
-func (that *JSONNode) Array(size int) *[]JSONNode {
- if that.t == TypeUndefined {
- that.t = TypeArray
- } else if that.t != TypeArray {
- panic(ErrorMultipleType)
- }
- if size < 0 {
- panic(ErrorArrayNegativeValue)
- }
- var min int
- if size < len(that.a) {
- min = size
- } else {
- min = len(that.a)
- }
- newa := make([]JSONNode, size)
- for i := 0; i < min; i++ {
- newa[i] = that.a[i]
- }
- that.a = newa
- return &(that.a)
-}
-
-//Val Turn this JSONNode to Value type and/or set that value to val
-func (that *JSONNode) Val(val interface{}) {
- if that.t == TypeUndefined {
- that.t = TypeValue
- } else if that.t != TypeValue {
- panic(ErrorMultipleType)
- }
- rt := reflect.TypeOf(val)
- var finalval interface{}
- if val == nil {
- finalval = &val
- that.vChanged = true
- } else if rt.Kind() != reflect.Ptr {
- rv := reflect.ValueOf(val)
- var tmp reflect.Value
- if rv.CanAddr() {
- tmp = rv.Addr()
- } else {
- tmp = reflect.New(rt)
- tmp.Elem().Set(rv)
- }
- finalval = tmp.Interface()
- that.vChanged = true
- } else {
- finalval = val
- }
- that.v = finalval
-}
-
-//Get Return value of a TypeValue as interface{}
-func (that *JSONNode) Get() interface{} {
- if that.t != TypeValue {
- panic(ErrorRetrieveUserValue)
- }
- if that.vChanged {
- rv := reflect.ValueOf(that.v)
- return rv.Elem().Interface()
- }
- return that.v
-}
-
-//GetKeys Return a slice interface that represent the keys to use with the At fonction (Works only on TypeMap and TypeArray)
-func (that *JSONNode) GetKeys() []interface{} {
- var ret []interface{}
- switch that.t {
- case TypeMap:
- nb := len(that.m)
- ret = make([]interface{}, nb)
- for key := range that.m {
- nb--
- ret[nb] = key
- }
- case TypeArray:
- nb := len(that.a)
- ret = make([]interface{}, nb)
- for nb > 0 {
- nb--
- ret[nb] = nb
- }
- default:
- panic(ErrorGetKeys)
- }
- return ret
-}
-
-//Len Return the length of the current Node
-//
-// if TypeUndefined return 0
-//
-// if TypeValue return 1
-//
-// if TypeArray return the size of the array
-//
-// if TypeMap return the size of the map
-func (that *JSONNode) Len() int {
- var ret int
- switch that.t {
- case TypeMap:
- ret = len(that.m)
- case TypeArray:
- ret = len(that.a)
- case TypeValue:
- ret = 1
- }
- return ret
-}
-
-//SetType Is use to set the Type of a node and return the current Node you are working on
-func (that *JSONNode) SetType(t JSONNodeType) *JSONNode {
- if that.t != TypeUndefined && that.t != t {
- panic(ErrorMultipleType)
- }
- if t >= typeError {
- panic(ErrorUnknowType)
- }
- that.t = t
- switch t {
- case TypeMap:
- that.m = make(map[string]*JSONNode, 0)
- case TypeArray:
- that.a = make([]JSONNode, 0)
- case TypeValue:
- that.Val(nil)
- }
- return that
-}
-
-//GetType Is use to Get the Type of a node
-func (that *JSONNode) GetType() JSONNodeType {
- return that.t
-}
-
-//Copy Will set this node like the one in argument. this node must be of type TypeUndefined
-//
-//if deepCopy is true we will copy all the children recursively else we will share the children
-//
-//return the current JSONNode
-func (that *JSONNode) Copy(other *JSONNode, deepCopy bool) *JSONNode {
- if that.t != TypeUndefined {
- panic(ErrorCopyType)
- }
-
- if other.t == TypeValue {
- *that = *other
- } else if other.t == TypeArray {
- if !deepCopy {
- *that = *other
- } else {
- that.Array(len(other.a))
- for i := range other.a {
- that.At(i).Copy(other.At(i), deepCopy)
- }
- }
- } else if other.t == TypeMap {
- that.SetType(other.t)
- if !deepCopy {
- for val := range other.m {
- that.m[val] = other.m[val]
- }
- } else {
- for val := range other.m {
- that.Map(val).Copy(other.At(val), deepCopy)
- }
- }
- }
- return that
-}
-
-
-//Unset Will unset everything in the JSONnode. All the children data will be lost
-func (that *JSONNode) Unset() {
- *that = JSONNode{}
-}
-
-//DelKey will remove a key in the map.
-//
-//return the current JSONNode.
-func (that *JSONNode) DelKey(key string) *JSONNode {
- if that.t != TypeMap {
- panic(ErrorDeleteKey)
- }
- delete(that.m, key)
- return that
-}
-
-//UnmarshalDontExpand set or not if Unmarshall will generate anything in that JSONNode and its children
-//
-//val: will change the expanding rules for this node
-//
-//- The type wont be change for any type
-//
-//- Array wont grow
-//
-//- New keys wont be added to Map
-//
-//- Values set to nil "*.Val(nil)*" will be turn into the type decide by Json
-//
-//- It will respect any current mapping and will return errors if needed
-//
-//recurse: if true, it will set all the children of that JSONNode with val
-func (that *JSONNode) UnmarshalDontExpand(val bool, recurse bool) *JSONNode {
- that.dontExpand = val
- if recurse {
- switch that.t {
- case TypeMap:
- for k := range that.m {
- that.m[k].UnmarshalDontExpand(val, recurse)
- }
- case TypeArray:
- for k := range that.a {
- that.a[k].UnmarshalDontExpand(val, recurse)
- }
- }
- }
- return that
-}
-
-//MarshalJSON Make JSONNode a Marshaler Interface compatible
-func (that *JSONNode) MarshalJSON() ([]byte, error) {
- var ret []byte
- var err error
- switch that.t {
- case TypeMap:
- ret, err = json.Marshal(that.m)
- case TypeArray:
- ret, err = json.Marshal(that.a)
- case TypeValue:
- ret, err = json.Marshal(that.v)
- default:
- ret, err = json.Marshal(nil)
- }
- if err != nil {
- return nil, err
- }
- return ret, err
-}
-
-func (that *JSONNode) unmarshalMap(data []byte) error {
- tmp := make(map[string]json.RawMessage)
- err := json.Unmarshal(data, &tmp)
- if err != nil {
- return err
- }
- for k := range tmp {
- if _, ok := that.m[k]; ok {
- err := json.Unmarshal(tmp[k], that.m[k])
- if err != nil {
- return err
- }
- } else if !that.dontExpand {
- err := json.Unmarshal(tmp[k], that.Map(k))
- if err != nil {
- return err
- }
- }
- }
- return nil
-}
-
-func (that *JSONNode) unmarshalArray(data []byte) error {
- var tmp []json.RawMessage
- err := json.Unmarshal(data, &tmp)
- if err != nil {
- return err
- }
- for i := len(tmp) - 1; i >= 0; i-- {
- if !that.dontExpand || i < len(that.a) {
- err := json.Unmarshal(tmp[i], that.At(i))
- if err != nil {
- return err
- }
- }
- }
- return nil
-}
-
-func (that *JSONNode) unmarshalValue(data []byte) error {
- if that.v != nil {
- return json.Unmarshal(data, that.v)
- }
- var tmp interface{}
- err := json.Unmarshal(data, &tmp)
- if err != nil {
- return err
- }
- that.Val(tmp)
- return nil
-}
-
-//UnmarshalJSON Make JSONNode a Unmarshaler Interface compatible
-func (that *JSONNode) UnmarshalJSON(data []byte) error {
- if len(data) == 0 {
- return nil
- }
- if that.dontExpand && that.t == TypeUndefined {
- return nil
- }
- if that.t == TypeValue {
- return that.unmarshalValue(data)
- }
- if data[0] == '{' {
- if that.t != TypeMap && that.t != TypeUndefined {
- return ErrorTypeUnmarshaling
- }
- return that.unmarshalMap(data)
- }
- if data[0] == '[' {
- if that.t != TypeArray && that.t != TypeUndefined {
- return ErrorTypeUnmarshaling
- }
- return that.unmarshalArray(data)
-
- }
- if that.t == TypeUndefined {
- return that.unmarshalValue(data)
- }
- return ErrorTypeUnmarshaling
-}
diff --git a/vendor/github.com/bennyscetbun/jsongo/print.go b/vendor/github.com/bennyscetbun/jsongo/print.go
deleted file mode 100644
index 6869918..0000000
--- a/vendor/github.com/bennyscetbun/jsongo/print.go
+++ /dev/null
@@ -1,74 +0,0 @@
-package jsongo
-
-import (
- "fmt"
- "regexp"
- "strings"
-)
-
-//Thanks https://github.com/chuckpreslar/inflect for the UpperCamelCase
-
-// Split's a string so that it can be converted to a different casing.
-// Splits on underscores, hyphens, spaces and camel casing.
-func split(str string) []string {
- // FIXME: This isn't a perfect solution.
- // ex. WEiRD CaSINg (Support for 13 year old developers)
- return strings.Split(regexp.MustCompile(`-|_|([a-z])([A-Z])`).ReplaceAllString(strings.Trim(str, `-|_| `), `$1 $2`), ` `)
-}
-
-// UpperCamelCase converts a string to it's upper camel case version.
-func UpperCamelCase(str string) string {
- pieces := split(str)
-
- for index, s := range pieces {
- pieces[index] = fmt.Sprintf(`%v%v`, strings.ToUpper(string(s[0])), strings.ToLower(s[1:]))
- }
-
- return strings.Join(pieces, ``)
-}
-
-func (that *JSONNode) printValue(indentlevel int, indentchar string) {
- fmt.Printf(" %T ", that.Get())
-}
-
-func (that *JSONNode) printMap(indentlevel int, indentchar string) {
- fmt.Printf(" struct {\n")
- for key := range that.m {
- printfindent(indentlevel+1, indentchar, "%s", UpperCamelCase(key))
- that.m[key].print(indentlevel+1, indentchar)
- fmt.Printf(" `json:\"%s\"`\n", key)
- }
- printfindent(indentlevel, indentchar, "}")
-}
-
-func (that *JSONNode) printArray(indentlevel int, indentchar string) {
- if len(that.a) == 0 {
- fmt.Printf(" []interface{} ")
- return
- }
- fmt.Printf(" [] ")
- for key := range that.a {
- that.a[key].print(indentlevel+1, indentchar)
- break
- }
-}
-
-//DebugProspect Print all the data the we ve got on a node and all it s children
-func (that *JSONNode) print(indentlevel int, indentchar string) {
- switch that.t {
- case TypeValue:
- that.printValue(indentlevel, indentchar)
- case TypeMap:
- that.printMap(indentlevel, indentchar)
- case TypeArray:
- that.printArray(indentlevel, indentchar)
- case TypeUndefined:
- printfindent(indentlevel, indentchar, "Is of Type: TypeUndefined\n")
- }
-}
-
-//Print Print all the data the we ve got on a node and all it s children as a go struct :) (FOR DEV PURPOSE)
-func (that *JSONNode) Print() {
- that.print(0, "\t")
- fmt.Printf("\n")
-}