Documentation ¶
Overview ¶
Package yomap is a nifty Go-based data structure package, affording the user with extremely useful capabilities. It aims to be useful and reliable for people who use map[string]interfaces{} often.
Please understand this is a very early release; proceed with caution.
Features
- Generally eases frustration associated with the nuances of map[string]interface{} management
- Plurality support (type vs. []type distinction)
- Reduces the number of instances where switch-based type assertion, conditional if-statements, etc., are needed
- Easy-to-read code with a simple usage syntax
- At present, no explicit error handling necessary for use
- Multi-level context support (experimental, but promising!)
Planned Features
- More tests! More examples! Way, way more.
- Pointer support per type, with associated functions
- Separate "extras" branch (yotool/yomap/extras) to harbor the following for those who want them:
- Built-in "github.com/nqd/flat" support for flattening/unflattening of logical hierarchies
- Advanced permutations of standard (core) features, enhanced withf features from imported packages such as "reflect", "strings", etc.
Credit ¶
Author: Jesse Coretta
Special thanks to Jason Mansfield for his awesome document (https://www.clinicallyawesome.com/2019/06/the-scenic-route-to-go-interfaces.html) that inspired this package.
Hierarchical Path Logic ¶
Starting with version 0.2.0, yotool/yomap now supports multi-level context handling to virtually infinite proportions.
Although all relevant functions have had their string-based input signature replaced by arrays of interfaces, coordinates are provides as string slices ([]string) which are subsequently type-asserted and digested as needed.
For example, let's say you have a YoMap structure not unlike the following:
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolString`: `this is pretty awesome!`, `lameString`: `I don't like cats`, }, }, }, }
And let's say you want to delete the `lameString` key because, come on, who doesn't like cats?! That's just crazy.
You can simply do:
path = []string{`firstLevel`,`secondLevel`,`thirdLevel`,`lameString`} ym.Delete(path)
If you're already importing the "strings" package, you can make your life easier by writing a wrapper function around strings.Split() that converts friendly dotted-paths, such as the following string, into the []string notation YoMap expects (and perhaps vice versa via strings.Join()):
// "strings" can convert ... `firstLevel.secondLevel.thirdLevel` ... to or from ... []string{`firstLevel`,`secondLevel`,`thirdLevel`}
As a reminder, YoMap is designed to be lightweight and, currently, imports only the "fmt" package for a very small handful of corner cases. As such, we sought not to import "strings" for such a singular and trivial task that should be easy for the user to handle.
Memory Allocation ¶
With regards to nested YoMaps, when invoking the YoMap.Reset() function respectively, the YoMap is not simply deleted as a typical key/value "delete" built-in operation, and then replaced, nor is it overwritten out-right.
Instead, a for-loop is invoked that will traverse and delete each of its subordinate keys individually.
The reason is that memory allocation can be re-used so long as the actual "housing object" remains. In high-volume scenarios where an object may persist for extended periods of time, this may be quite an important feature.
In the case of actual DELETES of subordinate YoMap instances, the above (Reset()) is run followed by a final YoMap.Delete of the specified object key itself.
Index ¶
- Constants
- type YoMap
- func (c YoMap) BoolInBools(ss ...interface{}) bool
- func (c YoMap) BoolInInterfaces(ss ...interface{}) bool
- func (c YoMap) ByteInBytes(ss ...interface{}) bool
- func (c YoMap) ByteInInterfaces(ss ...interface{}) bool
- func (c YoMap) Complex128InComplex128s(ss ...interface{}) bool
- func (c YoMap) Complex128InInterfaces(ss ...interface{}) bool
- func (c YoMap) Complex64InComplex64s(ss ...interface{}) bool
- func (c YoMap) Complex64InInterfaces(ss ...interface{}) bool
- func (c YoMap) Delete(s ...interface{})
- func (c YoMap) Elements(s ...interface{}) int
- func (c YoMap) ErrorInErrors(ss ...interface{}) bool
- func (c YoMap) ErrorInInterfaces(ss ...interface{}) bool
- func (c YoMap) Float32InFloat32s(ss ...interface{}) bool
- func (c YoMap) Float32InInterfaces(ss ...interface{}) bool
- func (c YoMap) Float64InFloat64s(ss ...interface{}) bool
- func (c YoMap) Float64InInterfaces(ss ...interface{}) bool
- func (c YoMap) Get(s ...interface{}) interface{}
- func (c YoMap) GetBoolEquals(kv ...interface{}) bool
- func (c YoMap) GetByteEquals(kv ...interface{}) bool
- func (c YoMap) GetBytes(s ...interface{}) []byte
- func (c YoMap) GetBytesEquals(kv ...interface{}) bool
- func (c YoMap) GetComplex128Equals(kv ...interface{}) bool
- func (c YoMap) GetComplex64Equals(kv ...interface{}) bool
- func (c YoMap) GetError(s ...interface{}) error
- func (c YoMap) GetErrorEquals(kv ...interface{}) bool
- func (c YoMap) GetFloat32Equals(kv ...interface{}) bool
- func (c YoMap) GetFloat64Equals(kv ...interface{}) bool
- func (c YoMap) GetInt16Equals(kv ...interface{}) bool
- func (c YoMap) GetInt32Equals(kv ...interface{}) bool
- func (c YoMap) GetInt64Equals(kv ...interface{}) bool
- func (c YoMap) GetInt8Equals(kv ...interface{}) bool
- func (c YoMap) GetIntEquals(kv ...interface{}) bool
- func (c YoMap) GetRuneEquals(kv ...interface{}) bool
- func (c YoMap) GetString(s ...interface{}) string
- func (c YoMap) GetStringEquals(kv ...interface{}) bool
- func (c YoMap) GetUint16Equals(kv ...interface{}) bool
- func (c YoMap) GetUint32Equals(kv ...interface{}) bool
- func (c YoMap) GetUint64Equals(kv ...interface{}) bool
- func (c YoMap) GetUint8Equals(kv ...interface{}) bool
- func (c YoMap) GetUintEquals(kv ...interface{}) bool
- func (c YoMap) GetYoMap(s ...interface{}) YoMap
- func (c YoMap) Has(s ...interface{}) bool
- func (c YoMap) Int16InInt16s(ss ...interface{}) bool
- func (c YoMap) Int16InInterfaces(ss ...interface{}) bool
- func (c YoMap) Int32InInt32s(ss ...interface{}) bool
- func (c YoMap) Int32InInterfaces(ss ...interface{}) bool
- func (c YoMap) Int64InInt64s(ss ...interface{}) bool
- func (c YoMap) Int64InInterfaces(ss ...interface{}) bool
- func (c YoMap) Int8InInt8s(ss ...interface{}) bool
- func (c YoMap) Int8InInterfaces(ss ...interface{}) bool
- func (c YoMap) IntInInterfaces(ss ...interface{}) bool
- func (c YoMap) IntInInts(ss ...interface{}) bool
- func (c YoMap) IsBool(s ...interface{}) bool
- func (c YoMap) IsBools(s ...interface{}) bool
- func (c YoMap) IsByte(s ...interface{}) bool
- func (c YoMap) IsBytes(s ...interface{}) bool
- func (c YoMap) IsComplex128(s ...interface{}) bool
- func (c YoMap) IsComplex128s(s ...interface{}) bool
- func (c YoMap) IsComplex64(s ...interface{}) bool
- func (c YoMap) IsComplex64s(s ...interface{}) bool
- func (c YoMap) IsError(s ...interface{}) bool
- func (c YoMap) IsErrors(s ...interface{}) bool
- func (c YoMap) IsFloat32(s ...interface{}) bool
- func (c YoMap) IsFloat32s(s ...interface{}) bool
- func (c YoMap) IsFloat64(s ...interface{}) bool
- func (c YoMap) IsFloat64s(s ...interface{}) bool
- func (c YoMap) IsInt(s ...interface{}) bool
- func (c YoMap) IsInt16(s ...interface{}) bool
- func (c YoMap) IsInt16s(s ...interface{}) bool
- func (c YoMap) IsInt32(s ...interface{}) bool
- func (c YoMap) IsInt32s(s ...interface{}) bool
- func (c YoMap) IsInt64(s ...interface{}) bool
- func (c YoMap) IsInt64s(s ...interface{}) bool
- func (c YoMap) IsInt8(s ...interface{}) bool
- func (c YoMap) IsInt8s(s ...interface{}) bool
- func (c YoMap) IsInterfaces(s ...interface{}) bool
- func (c YoMap) IsInts(s ...interface{}) bool
- func (c YoMap) IsNil(s ...interface{}) bool
- func (c YoMap) IsRune(s ...interface{}) bool
- func (c YoMap) IsRunes(s ...interface{}) bool
- func (c YoMap) IsString(s ...interface{}) bool
- func (c YoMap) IsStrings(s ...interface{}) bool
- func (c YoMap) IsUint(s ...interface{}) bool
- func (c YoMap) IsUint16(s ...interface{}) bool
- func (c YoMap) IsUint16s(s ...interface{}) bool
- func (c YoMap) IsUint32(s ...interface{}) bool
- func (c YoMap) IsUint32s(s ...interface{}) bool
- func (c YoMap) IsUint64(s ...interface{}) bool
- func (c YoMap) IsUint64s(s ...interface{}) bool
- func (c YoMap) IsUint8(s ...interface{}) bool
- func (c YoMap) IsUint8s(s ...interface{}) bool
- func (c YoMap) IsUintptr(s ...interface{}) bool
- func (c YoMap) IsUintptrs(s ...interface{}) bool
- func (c YoMap) IsUints(s ...interface{}) bool
- func (c YoMap) IsYoMap(s ...interface{}) bool
- func (c YoMap) IsYoMaps(s ...interface{}) bool
- func (c YoMap) Lacks(s ...interface{}) bool
- func (c YoMap) Len(s ...interface{}) int
- func (c YoMap) NilInInterfaces(ss ...interface{}) bool
- func (c YoMap) Ready(s ...interface{}) bool
- func (c YoMap) Reset(s ...interface{})
- func (c YoMap) RuneInInterfaces(ss ...interface{}) bool
- func (c YoMap) RuneInRunes(ss ...interface{}) bool
- func (c YoMap) Set(s ...interface{})
- func (c YoMap) String(s ...interface{})
- func (c YoMap) StringInInterfaces(ss ...interface{}) bool
- func (c YoMap) StringInStrings(ss ...interface{}) bool
- func (c YoMap) TypeOf(s ...interface{}) string
- func (c YoMap) Uint16InInterfaces(ss ...interface{}) bool
- func (c YoMap) Uint16InUint16s(ss ...interface{}) bool
- func (c YoMap) Uint32InInterfaces(ss ...interface{}) bool
- func (c YoMap) Uint32InUint32s(ss ...interface{}) bool
- func (c YoMap) Uint64InInterfaces(ss ...interface{}) bool
- func (c YoMap) Uint64InUint64s(ss ...interface{}) bool
- func (c YoMap) Uint8InInterfaces(ss ...interface{}) bool
- func (c YoMap) Uint8InUint8s(ss ...interface{}) bool
- func (c YoMap) UintInInterfaces(ss ...interface{}) bool
- func (c YoMap) UintInUints(ss ...interface{}) bool
- func (c YoMap) UintptrInInterfaces(ss ...interface{}) bool
- func (c YoMap) UintptrInUintptrs(ss ...interface{}) bool
Examples ¶
- New
- YoMap.BoolInBools
- YoMap.BoolInInterfaces
- YoMap.ByteInBytes
- YoMap.ByteInInterfaces
- YoMap.Complex128InComplex128s
- YoMap.Complex128InInterfaces
- YoMap.Complex64InComplex64s
- YoMap.Complex64InInterfaces
- YoMap.Delete
- YoMap.Elements
- YoMap.ErrorInErrors
- YoMap.ErrorInInterfaces
- YoMap.Float32InFloat32s
- YoMap.Float32InInterfaces
- YoMap.Float64InFloat64s
- YoMap.Float64InInterfaces
- YoMap.Get
- YoMap.GetBoolEquals
- YoMap.GetByteEquals
- YoMap.GetBytes
- YoMap.GetBytesEquals
- YoMap.GetComplex128Equals
- YoMap.GetComplex64Equals
- YoMap.GetError
- YoMap.GetErrorEquals
- YoMap.GetFloat32Equals
- YoMap.GetFloat64Equals
- YoMap.GetInt16Equals
- YoMap.GetInt32Equals
- YoMap.GetInt64Equals
- YoMap.GetInt8Equals
- YoMap.GetIntEquals
- YoMap.GetRuneEquals
- YoMap.GetString
- YoMap.GetStringEquals
- YoMap.GetUint16Equals
- YoMap.GetUint32Equals
- YoMap.GetUint64Equals
- YoMap.GetUint8Equals
- YoMap.GetUintEquals
- YoMap.GetYoMap
- YoMap.Has
- YoMap.Int16InInt16s
- YoMap.Int16InInterfaces
- YoMap.Int32InInt32s
- YoMap.Int32InInterfaces
- YoMap.Int64InInt64s
- YoMap.Int64InInterfaces
- YoMap.Int8InInt8s
- YoMap.Int8InInterfaces
- YoMap.IntInInterfaces
- YoMap.IntInInts
- YoMap.IsBool
- YoMap.IsBools
- YoMap.IsByte
- YoMap.IsBytes
- YoMap.IsComplex128
- YoMap.IsComplex128s
- YoMap.IsComplex64
- YoMap.IsComplex64s
- YoMap.IsError
- YoMap.IsErrors
- YoMap.IsFloat32
- YoMap.IsFloat32s
- YoMap.IsFloat64
- YoMap.IsFloat64s
- YoMap.IsInt
- YoMap.IsInt16
- YoMap.IsInt16s
- YoMap.IsInt32
- YoMap.IsInt32s
- YoMap.IsInt64
- YoMap.IsInt64s
- YoMap.IsInt8
- YoMap.IsInt8s
- YoMap.IsInterfaces
- YoMap.IsInts
- YoMap.IsNil
- YoMap.IsRune
- YoMap.IsRunes
- YoMap.IsString
- YoMap.IsStrings
- YoMap.IsUint
- YoMap.IsUint16
- YoMap.IsUint16s
- YoMap.IsUint32
- YoMap.IsUint32s
- YoMap.IsUint64
- YoMap.IsUint64s
- YoMap.IsUint8
- YoMap.IsUint8s
- YoMap.IsUintptr
- YoMap.IsUintptrs
- YoMap.IsUints
- YoMap.IsYoMap
- YoMap.IsYoMaps
- YoMap.Lacks
- YoMap.Len
- YoMap.NilInInterfaces
- YoMap.Ready
- YoMap.Reset
- YoMap.RuneInInterfaces
- YoMap.RuneInRunes
- YoMap.Set
- YoMap.String
- YoMap.StringInInterfaces
- YoMap.StringInStrings
- YoMap.TypeOf
- YoMap.Uint16InInterfaces
- YoMap.Uint16InUint16s
- YoMap.Uint32InInterfaces
- YoMap.Uint32InUint32s
- YoMap.Uint64InInterfaces
- YoMap.Uint64InUint64s
- YoMap.Uint8InInterfaces
- YoMap.Uint8InUint8s
- YoMap.UintInUints
- YoMap.UintptrInInterfaces
- YoMap.UintptrInUintptrs
Constants ¶
const Version = `0.3.8`
Version contains the string-form of the Semantic Version Number for this release. See https://semver.org for more information.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type YoMap ¶
type YoMap map[string]interface{}
YoMap is merely a type alias for map[string]interface{}. It is from this alias that new methods can be extended.
func New ¶
func New(l ...interface{}) YoMap
New will initialize and return an instance of YoMap. An optional integer will be accepted, representing the desired memory allocation (length).
Example ¶
// Uses make behind-the-scenes ... ym := New() // Or, allocate a specific amount of memory (make's "len" parameter) .. // ym := New(30) // Alternatively, you can craft your YoMap manually, though // its not as efficient in terms of memory ... // ym := YoMap{`myKey`:`someValue`} ym.Set([]string{`coolString`}, `true`) ym.Set([]string{`coolBool`}, true) fmt.Printf("This new YoMap instance is %d entries long", ym.Len())
Output: This new YoMap instance is 2 entries long
func (YoMap) BoolInBools ¶
BoolInBools returns a bool indicating whether the value is present within a given array of same type.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolBools`: []bool{true, false, true, false}, }, }, }, } var coolBools []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolBools`} if ym.BoolInBools(coolBools, true) { fmt.Println("Desired boolean found in array of bools") }
Output: Desired boolean found in array of bools
func (YoMap) BoolInInterfaces ¶
BoolInInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see BoolInBools() example, substituting for type as appropriate ... //
Output:
func (YoMap) ByteInBytes ¶
ByteInBytes returns a bool indicating whether the value is present within a given array of same type.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolBytes`: []byte{byte(0x2)}, }, }, }, } var coolBytes []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolBytes`} if ym.ByteInBytes(coolBytes, byte(0x2)) { fmt.Println("Desired byte sequence found in array of bytes") }
Output: Desired byte sequence found in array of bytes
func (YoMap) ByteInInterfaces ¶
ByteInInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see ByteInBytes() example, substituting for type as appropriate ... //
Output:
func (YoMap) Complex128InComplex128s ¶
Complex128InComplex128s returns a bool indicating whether the value is present within a given array of same type.
Example ¶
// Some complex numbers c128 := 0.17 + 0.4i c128a := 0.61 + 0.4i c128b := 0.34 + 0.1i c128c := 0.59 + 0.5i ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolNumbers`: []complex128{complex128(c128), complex128(c128a), complex128(c128b), complex128(c128c)}, }, }, }, } var coolNumbers []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolNumbers`} if ym.Complex128InComplex128s(coolNumbers, complex128(c128a)) { fmt.Println("Desired complex128 found in array of complex128s") }
Output: Desired complex128 found in array of complex128s
func (YoMap) Complex128InInterfaces ¶
Complex128InInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see the Complex128inComplex128s() example, substituting for type as appropriate ...//
Output:
func (YoMap) Complex64InComplex64s ¶
Complex64InComplex64s returns a bool indicating whether the value is present within a given array of same type.
Example ¶
// Some complex numbers c64 := 0.17 + 0.4i c64a := 0.61 + 0.4i c64b := 0.34 + 0.1i c64c := 0.59 + 0.5i ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolNumbers`: []complex64{complex64(c64), complex64(c64a), complex64(c64b), complex64(c64c)}, }, }, }, } var coolNumbers []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolNumbers`} if ym.Complex64InComplex64s(coolNumbers, complex64(c64a)) { fmt.Println("Desired complex64 found in array of complex64s") }
Output: Desired complex64 found in array of complex64s
func (YoMap) Complex64InInterfaces ¶
Complex64InInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see the Complex64inComplex64s() example, substituting for type as appropriate ...//
Output:
func (YoMap) Delete ¶
func (c YoMap) Delete(s ...interface{})
Delete will delete the named entry (s) from an instance of YoMap.
Example ¶
ym := YoMap{ `coolString`: `true`, `coolBytes`: []byte(`...someBytes...`), `coolBool`: true, } ym.Delete([]string{`coolString`}) fmt.Printf("YoMap should be %d entries long now", ym.Len())
Output: YoMap should be 2 entries long now
func (YoMap) Elements ¶
Elements will return the number of non-nil array elements perceived within a YoMap key's value assignment. If a value is not an array, but is present, 1 is returned. If nonexistent, 0 is returned.
Example ¶
// Some weird array of mixed-types ifs := make([]interface{}, 5) ifs[0] = float32(3.14) ifs[1] = float64(3.14159) ifs[2] = []byte(`{"jsonKey": "someValue"}`) ifs[3] = string("Testing 1 2 3") //ifs[4] = bool(true) // leave one unpopulated ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `mixed`: ifs, `thirdLevel`: YoMap{ `coolFloats`: []float64{3.14, 3.1415, 3.14159}, }, }, }, `coolString`: `very cool`, `coolStrings`: []string{`string1`, `string2`, `string3`, `string4`, `string5`, `string6`}, `coolInts`: []int{1, 2, 3, 4}, `coolBools`: []bool{true, false, true, false, true}, } els := ym.Elements([]string{`coolStrings`}) eli := ym.Elements([]string{`coolInts`}) elb := ym.Elements([]string{`coolBools`}) elf := ym.Elements([]string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolFloats`}) elm := ym.Elements([]string{`firstLevel`, `secondLevel`, `mixed`}) lie := ym.Elements([]string{`coolString`}) empty := ym.Elements() fmt.Printf("Strings: %d, Ints: %d, Bools: %d, Floats: %d, Mixed: %d, Single String: %d, Empty: %d", els, eli, elb, elf, elm, lie, empty)
Output: Strings: 6, Ints: 4, Bools: 5, Floats: 3, Mixed: 4, Single String: 1, Empty: 0
func (YoMap) ErrorInErrors ¶
ErrorInErrors returns a bool indicating whether the value is present within a given array of same type.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []error{fmt.Errorf("Error1"), fmt.Errorf("Error2"), fmt.Errorf("Error3")}, }, }, }, } var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.ErrorInErrors(coolMulti, fmt.Errorf("Error1")) { fmt.Println("Desired error found in array of errors") }
Output: Desired error found in array of errors
func (YoMap) ErrorInInterfaces ¶
ErrorInInterfaces returns a bool indicating whether the value is present within a given array interfaces.
Example ¶
// ... see the ErrorInErrors() example, substituting for type as appropriate ...//
Output:
func (YoMap) Float32InFloat32s ¶
Float32InFloat32s returns a bool indicating whether the value is present within a given array of same type.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolNumbers`: []float32{3.14, 3.141, 3.1415, 3.14159}, }, }, }, } var coolNumbers []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolNumbers`} if ym.Float32InFloat32s(coolNumbers, float32(3.14159)) { fmt.Println("Desired float32 found in array of float32s") }
Output: Desired float32 found in array of float32s
func (YoMap) Float32InInterfaces ¶
Float32InInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see Float32InFloat32s() example, substituting for type as appropriate ... //
Output:
func (YoMap) Float64InFloat64s ¶
Float64InFloat64s returns a bool indicating whether the value is present within a given array of same type.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolNumbers`: []float64{3.14, 3.141, 3.1415, 3.14159}, }, }, }, } var coolNumbers []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolNumbers`} if ym.Float64InFloat64s(coolNumbers, float64(3.14159)) { fmt.Println("Desired float64 found in array of float64s") }
Output: Desired float64 found in array of float64s
func (YoMap) Float64InInterfaces ¶
Float64InInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see Float64InFloat64s() example, substituting for type as appropriate ... //
Output:
func (YoMap) Get ¶
func (c YoMap) Get(s ...interface{}) interface{}
Get will return the interface{} value of the named key (s), should it exists, otherwise nil will be returned. Anything returned via this function must later be type asserted properly.
Example ¶
ym := YoMap{ `coolString`: true, `coolBytes`: []byte(`bytes`), `coolBool`: true, } cool := ym.Get([]string{`coolBool`}) // will be an interface{} unless type-asserted! if _, isBool := cool.(bool); isBool { fmt.Printf("It's a bool? %v", isBool) }
Output: It's a bool? true
func (YoMap) GetBoolEquals ¶
GetBoolEquals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolBool`: true, }, }, }, } var ( coolBool []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolBool`} ) if ym.GetBoolEquals(coolBool, true) { fmt.Println("coolBool matched!") }
Output: coolBool matched!
func (YoMap) GetByteEquals ¶
GetByteEquals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolByte`: byte(0x1), }, }, }, } var ( coolByte []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolByte`} ) if ym.GetByteEquals(coolByte, byte(0x1)) { fmt.Println("coolByte matched!") }
Output: coolByte matched!
func (YoMap) GetBytes ¶
GetBytes is a convenience method specifically tuned for byte sequences. If not a []byte, or if the search key is nonexistent, an empty byte sequence ([]byte(“)) is returned. This method is provided due to a low degree of ambiguity with regards to the return type.
Example ¶
ym := YoMap{ `coolString`: true, `coolBytes`: []byte(`false`), `coolBool`: true, } ym.Set([]string{`coolBytes`}, []byte(`true`)) coolBytes := ym.GetBytes([]string{`coolBytes`}) // will be []byte, no type assertion needed fmt.Printf("%s: %v", string(coolBytes), coolBytes)
Output: true: [116 114 117 101]
func (YoMap) GetBytesEquals ¶
GetBytesEquals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolBytes`: []byte(`{"someKey":"someValue"}`), }, }, }, } var ( coolBytes []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolBytes`} ) if ym.GetBytesEquals(coolBytes, []byte(`{"someKey":"someValue"}`)) { fmt.Println("coolBytes matched!") }
Output: coolBytes matched!
func (YoMap) GetComplex128Equals ¶
GetComplex128Equals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolComplex128`: 0.61 + 0.4i, }, }, }, } var ( coolComplex128 []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolComplex128`} ) if ym.GetComplex128Equals(coolComplex128, 0.61+0.4i) { fmt.Println("coolComplex128 matched!") }
Output: coolComplex128 matched!
func (YoMap) GetComplex64Equals ¶
GetComplex64Equals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolComplex64`: complex64(0.61 + 0.4i), }, }, }, } var ( coolComplex64 []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolComplex64`} ) if ym.GetComplex64Equals(coolComplex64, complex64(0.61+0.4i)) { fmt.Println("coolComplex64 matched!") }
Output: coolComplex64 matched!
func (YoMap) GetError ¶
GetError is a convenience method specifically tuned for the error type. If not an error, or if the search key is nonexistent, nil is returned.
Example ¶
ym := YoMap{ `coolError`: fmt.Errorf("This is a pretty rad error"), `coolBool`: true, } coolError := ym.GetError([]string{`coolError`}) // will be error, no type assertion needed fmt.Printf("%s", coolError.Error())
Output: This is a pretty rad error
func (YoMap) GetErrorEquals ¶
GetErrorEquals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolError`: fmt.Errorf("This is a pretty rad error"), }, }, }, } var ( coolError []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolError`} ) if ym.GetErrorEquals(coolError, fmt.Errorf("This is a pretty rad error")) { fmt.Println("coolError matched!") }
Output: coolError matched!
func (YoMap) GetFloat32Equals ¶
GetFloat32Equals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolFloat32`: float32(3.14), }, }, }, } var ( coolFloat32 []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolFloat32`} ) if ym.GetFloat32Equals(coolFloat32, float32(3.14)) { fmt.Println("coolFloat32 matched!") }
Output: coolFloat32 matched!
func (YoMap) GetFloat64Equals ¶
GetFloat64Equals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolFloat64`: 3.14, }, }, }, } var ( coolFloat64 []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolFloat64`} ) if ym.GetFloat64Equals(coolFloat64, 3.14) { fmt.Println("coolFloat64 matched!") }
Output: coolFloat64 matched!
func (YoMap) GetInt16Equals ¶
GetInt16Equals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
// See GetIntEquals() example, substituting for desired int type
Output:
func (YoMap) GetInt32Equals ¶
GetInt32Equals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
// See GetIntEquals() example, substituting for desired int type
Output:
func (YoMap) GetInt64Equals ¶
GetInt64Equals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
// See GetIntEquals() example, substituting for desired int type
Output:
func (YoMap) GetInt8Equals ¶
GetInt8Equals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
// See GetIntEquals() example, substituting for desired int type
Output:
func (YoMap) GetIntEquals ¶
GetIntEquals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolInt`: 42, }, }, }, } var ( coolInt []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolInt`} ) if ym.GetIntEquals(coolInt, 42) { fmt.Println("coolInt matched!") }
Output: coolInt matched!
func (YoMap) GetRuneEquals ¶
GetRuneEquals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolRune`: 'c', }, }, }, } var ( coolRune []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolRune`} ) if ym.GetRuneEquals(coolRune, 'c') { fmt.Println("coolRune matched!") }
Output: coolRune matched!
func (YoMap) GetString ¶
GetString is a convenience method specifically tuned for strings. If not a string, or if the search key is nonexistent, an empty string (“) is returned. This method is provided due to a low degree of ambiguity with regards to the return type.
Example ¶
ym := YoMap{ `coolString`: `false`, `coolBytes`: []byte(`false`), `coolBool`: true, } ym.Set([]string{`coolString`}, `true`) coolString := ym.GetString([]string{`coolString`}) // will be string, no type assertion needed fmt.Printf("%s", coolString)
Output: true
func (YoMap) GetStringEquals ¶
GetStringEquals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolString`: `cats rule!`, }, }, }, `coolKey`: `importantV@lu3`, } var ( coolString []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolString`} coolKey []string = []string{`coolKey`} ) if ym.GetStringEquals(coolKey, `importantV@lu3`) && ym.GetStringEquals(coolString, `cats rule!`) { fmt.Println("coolString and coolKey both matched!") }
Output: coolString and coolKey both matched!
func (YoMap) GetUint16Equals ¶
GetUint16Equals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
// See GetUintEquals() example, substituting for desired int type
Output:
func (YoMap) GetUint32Equals ¶
GetUint32Equals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
// See GetUintEquals() example, substituting for desired int type
Output:
func (YoMap) GetUint64Equals ¶
GetUint64Equals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
// See GetUintEquals() example, substituting for desired int type
Output:
func (YoMap) GetUint8Equals ¶
GetUint8Equals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
// See GetUintEquals() example, substituting for desired int type
Output:
func (YoMap) GetUintEquals ¶
GetUintEquals will return a bool indicating whether the provided key (k) exists and is assigned a value equal to the provided value (v).
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolUint`: uint(42), }, }, }, } var ( coolUint []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolUint`} ) if ym.GetUintEquals(coolUint, uint(42)) { fmt.Println("coolUint matched!") }
Output: coolUint matched!
func (YoMap) GetYoMap ¶
GetYoMap is a convenience method specifically tuned for the YoMap type. If not a YoMap, or if the search key is nonexistent, nil is returned. This method is provided due to a low degree of ambiguity with regards to the return type.
Example ¶
ym := YoMap{ `coolYoMap`: YoMap{ `otherCoolString`: false, `otherCoolBytes`: []byte(`false`), `coolBool`: true, }, `coolString`: `false`, `coolBytes`: []byte(`false`), `coolBool`: true, } cym := ym.GetYoMap([]string{`coolYoMap`}) // will be YoMap, no type assertion needed fmt.Printf("YoMap.CoolYoMap is %d entries long", cym.Len())
Output: YoMap.CoolYoMap is 3 entries long
func (YoMap) Has ¶
Has will return a bool if path exists
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolString`: `this is pretty awesome!`, `lameString`: `I don't like cats`, }, }, }, } var path []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolString`} if ym.Has(path) && ym.IsString(path) { g := ym.Get(path).(string) fmt.Printf("Found: %s", g) }
Output: Found: this is pretty awesome!
func (YoMap) Int16InInt16s ¶
Int16InInt16s returns a bool indicating whether the value is present within a given array of same type.
Example ¶
// ... see IntInInts() example, substituting for type as appropriate ... //
Output:
func (YoMap) Int16InInterfaces ¶
Int16InInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see IntInInts() example, substituting for type as appropriate ... //
Output:
func (YoMap) Int32InInt32s ¶
Int32InInt32s returns a bool indicating whether the value is present within a given array of same type.
Example ¶
// ... see IntInInts() example, substituting for type as appropriate ... //
Output:
func (YoMap) Int32InInterfaces ¶
Int32InInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see IntInInts() example, substituting for type as appropriate ... //
Output:
func (YoMap) Int64InInt64s ¶
Int64InInt64s returns a bool indicating whether the value is present within a given array of same type.
Example ¶
// ... see IntInInts() example, substituting for type as appropriate ... //
Output:
func (YoMap) Int64InInterfaces ¶
Int64InInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see IntInInts() example, substituting for type as appropriate ... //
Output:
func (YoMap) Int8InInt8s ¶
Int8InInt8s returns a bool indicating whether the value is present within a given array of same type.
Example ¶
// ... see IntInInts() example, substituting for type as appropriate ... //
Output:
func (YoMap) Int8InInterfaces ¶
Int8InInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see IntInInts() example, substituting for type as appropriate ... //
Output:
func (YoMap) IntInInterfaces ¶
IntInInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see IntInInts() example, substituting for type as appropriate ... //
Output:
func (YoMap) IntInInts ¶
IntInInts returns a bool indicating whether the value is present within a given array of same type.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolNumbers`: []int{1, 2, 3, 4}, }, }, }, } var coolNumbers []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolNumbers`} if ym.IntInInts(coolNumbers, 4) { fmt.Println("Desired int found in array of ints") }
Output: Desired int found in array of ints
func (YoMap) IsBool ¶
IsBool returns a bool indicating whether the value of key s within YoMap is of type bool.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: true, `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []bool{false, false, false, false, true}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsBool(coolSingle) && ym.IsBools(coolMulti) { fmt.Println("coolSingle is a bool, and coolMulti is an array of bools") }
Output: coolSingle is a bool, and coolMulti is an array of bools
func (YoMap) IsBools ¶
IsBools returns a bool indicating whether the value of key s within YoMap is of type []bool.
Example ¶
// ... see the IsBool() example ...//
Output:
func (YoMap) IsByte ¶
IsByte returns a bool indicating whether the value of key s within YoMap is of type byte.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: byte(0x1), `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []byte(`{"jsonKey": "jsonValue"}`), }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsByte(coolSingle) && ym.IsBytes(coolMulti) { fmt.Println("coolSingle is a byte, and coolMulti is an array of bytes") }
Output: coolSingle is a byte, and coolMulti is an array of bytes
func (YoMap) IsBytes ¶
IsBytes returns a bool indicating whether the value of key s within YoMap is of type []byte.
Example ¶
// ... see the IsByte() example ...//
Output:
func (YoMap) IsComplex128 ¶
IsComplex128 returns a bool indicating whether the value of key s within YoMap is of type complex128.
Example ¶
// Some complex numbers c128 := 0.17 + 0.4i c128a := 0.61 + 0.4i c128b := 0.34 + 0.1i c128c := 0.59 + 0.5i ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: c128, `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []complex128{c128a, c128b, c128c}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsComplex128(coolSingle) && ym.IsComplex128s(coolMulti) { fmt.Println("coolSingle is a complex128, and coolMulti is an array of complex128s") }
Output: coolSingle is a complex128, and coolMulti is an array of complex128s
func (YoMap) IsComplex128s ¶
IsComplex128s returns a bool indicating whether the value of key s within YoMap is of type []complex128.
Example ¶
// ... see the IsComplex128() example ...//
Output:
func (YoMap) IsComplex64 ¶
IsComplex64 returns a bool indicating whether the value of key s within YoMap is of type complex64.
Example ¶
// Some complex numbers c64 := 0.17 + 0.4i c64a := 0.61 + 0.4i c64b := 0.34 + 0.1i c64c := 0.59 + 0.5i ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: complex64(c64), `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []complex64{complex64(c64a), complex64(c64b), complex64(c64c)}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsComplex64(coolSingle) && ym.IsComplex64s(coolMulti) { fmt.Println("coolSingle is a complex64, and coolMulti is an array of complex64s") }
Output: coolSingle is a complex64, and coolMulti is an array of complex64s
func (YoMap) IsComplex64s ¶
IsComplex64s returns a bool indicating whether the value of key s within YoMap is of type []complex64.
Example ¶
// ... see the IsComplex64() example ...//
Output:
func (YoMap) IsError ¶
IsError returns a bool indicating whether the value of key s within YoMap is of type error.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: fmt.Errorf("Error 501: User dislikes cats"), `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []error{fmt.Errorf("Error1"), fmt.Errorf("Error2"), fmt.Errorf("Error3")}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsError(coolSingle) && ym.IsErrors(coolMulti) { fmt.Println("coolSingle is an error, and coolMulti is an array of errors") }
Output: coolSingle is an error, and coolMulti is an array of errors
func (YoMap) IsErrors ¶
IsErrors returns a bool indicating whether the value of key s within YoMap is of type []error.
Example ¶
// ... see the IsError() example ...//
Output:
func (YoMap) IsFloat32 ¶
IsFloat32 returns a bool indicating whether the value of key s within YoMap is of type float32.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: float32(3.14), `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []float32{3.14, 3.141, 3.1415}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsFloat32(coolSingle) && ym.IsFloat32s(coolMulti) { fmt.Println("coolSingle is a float32, and coolMulti is an array of float32s") }
Output: coolSingle is a float32, and coolMulti is an array of float32s
func (YoMap) IsFloat32s ¶
IsFloat32s returns a bool indicating whether the value of key s within YoMap is of type []float32.
Example ¶
// ... see the IsFloat32() example ...//
Output:
func (YoMap) IsFloat64 ¶
IsFloat64 returns a bool indicating whether the value of key s within YoMap is of type float64.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: float64(3.14), `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []float64{3.14, 3.141, 3.1415}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsFloat64(coolSingle) && ym.IsFloat64s(coolMulti) { fmt.Println("coolSingle is a float64, and coolMulti is an array of float64s") }
Output: coolSingle is a float64, and coolMulti is an array of float64s
func (YoMap) IsFloat64s ¶
IsFloat64s returns a bool indicating whether the value of key s within YoMap is of type []float64.
Example ¶
// ... see the IsFloat64() example ...//
Output:
func (YoMap) IsInt ¶
IsInt returns a bool indicating whether the value of key s within YoMap is of type int.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: int(3054957437), `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []int{0, -1, 78243, 342}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsInt(coolSingle) && ym.IsInts(coolMulti) { fmt.Println("coolSingle is a int, and coolMulti is an array of ints") }
Output: coolSingle is a int, and coolMulti is an array of ints
func (YoMap) IsInt16 ¶
IsInt16 returns a bool indicating whether the value of key s within YoMap is of type int16.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: int16(3054), `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []int16{0, -1, 782, 342}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsInt16(coolSingle) && ym.IsInt16s(coolMulti) { fmt.Println("coolSingle is a int, and coolMulti is an array of ints") }
Output: coolSingle is a int, and coolMulti is an array of ints
func (YoMap) IsInt16s ¶
IsInt16s returns a bool indicating whether the value of key s within YoMap is of type []int16.
Example ¶
// ... see the IsInt16() example ...//
Output:
func (YoMap) IsInt32 ¶
IsInt32 returns a bool indicating whether the value of key s within YoMap is of type int32.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: int32(3054957), `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []int32{0, -1, 78243, 342}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsInt32(coolSingle) && ym.IsInt32s(coolMulti) { fmt.Println("coolSingle is a int, and coolMulti is an array of ints") }
Output: coolSingle is a int, and coolMulti is an array of ints
func (YoMap) IsInt32s ¶
IsInt32s returns a bool indicating whether the value of key s within YoMap is of type []int32.
Example ¶
// ... see the IsInt32() example ...//
Output:
func (YoMap) IsInt64 ¶
IsInt64 returns a bool indicating whether the value of key s within YoMap is of type int64.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: int64(3054957437), `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []int64{0, -1, 78243, 342}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsInt64(coolSingle) && ym.IsInt64s(coolMulti) { fmt.Println("coolSingle is a int, and coolMulti is an array of ints") }
Output: coolSingle is a int, and coolMulti is an array of ints
func (YoMap) IsInt64s ¶
IsInt64s returns a bool indicating whether the value of key s within YoMap is of type []int64.
Example ¶
// ... see the IsInt64() example ...//
Output:
func (YoMap) IsInt8 ¶
IsInt8 returns a bool indicating whether the value of key s within YoMap is of type int8.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: int8(30), `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []int8{0, -1, 78, 42}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsInt8(coolSingle) && ym.IsInt8s(coolMulti) { fmt.Println("coolSingle is a int, and coolMulti is an array of ints") }
Output: coolSingle is a int, and coolMulti is an array of ints
func (YoMap) IsInt8s ¶
IsInt8s returns a bool indicating whether the value of key s within YoMap is of type []int8.
Example ¶
// ... see the IsInt8() example ...//
Output:
func (YoMap) IsInterfaces ¶
IsInterfaces returns a bool indicating whether the value of key s within YoMap is of type []interface{}.
Example ¶
// Some weird array of mixed-types ifs := make([]interface{}, 4) ifs[0] = float32(3.14) ifs[1] = float64(3.14159) ifs[2] = []byte(`{"jsonKey": "someValue"}`) ifs[3] = string("Testing 1 2 3") ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: ifs, }, }, }, } var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsInterfaces(coolMulti) { fmt.Println("coolMulti is an array of interfaces") }
Output: coolMulti is an array of interfaces
func (YoMap) IsInts ¶
IsInts returns a bool indicating whether the value of key s within YoMap is of type []int.
Example ¶
// ... see the IsInt() example ...//
Output:
func (YoMap) IsNil ¶
IsNil returns a bool indicating whether the value of key s within YoMap is defined **and** its value is nil. A nonexistent key does not mean nil!
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: nil, `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []error{nil, nil, nil}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} if ym.IsNil(coolSingle) { fmt.Println("coolSingle is a nil") }
Output: coolSingle is a nil
func (YoMap) IsRune ¶
IsRune returns a bool indicating whether the value of key s within YoMap is of type rune.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: 'c', `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []rune{'a', 'b', 'c'}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsRune(coolSingle) && ym.IsRunes(coolMulti) { fmt.Println("coolSingle is a rune, and coolMulti is an array of runes") }
Output: coolSingle is a rune, and coolMulti is an array of runes
func (YoMap) IsRunes ¶
IsRunes returns a bool indicating whether the value of key s within YoMap is of type []rune.
Example ¶
// ... see the IsRune() example ...//
Output:
func (YoMap) IsString ¶
IsString returns a bool indicating whether the value of key s within YoMap is of type string.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: `quite cool`, `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []string{`false`, `blarg`, `_____`, `Hello.`}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsString(coolSingle) && ym.IsStrings(coolMulti) { fmt.Println("coolSingle is a string, and coolMulti is an array of strings") }
Output: coolSingle is a string, and coolMulti is an array of strings
func (YoMap) IsStrings ¶
IsStrings returns a bool indicating whether the value of key s within YoMap is of type []string.
Example ¶
// ... see the IsString() example ...//
Output:
func (YoMap) IsUint ¶
IsUint returns a bool indicating whether the value of key s within YoMap is of type uint.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: uint(3054957437), `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []uint{0, 53, 78243, 342}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsUint(coolSingle) && ym.IsUints(coolMulti) { fmt.Println("coolSingle is a uint, and coolMulti is an array of uints") }
Output: coolSingle is a uint, and coolMulti is an array of uints
func (YoMap) IsUint16 ¶
IsUint16 returns a bool indicating whether the value of key s within YoMap is of type uint16.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: uint16(30545), `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []uint16{0, 53, 7243, 342}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsUint16(coolSingle) && ym.IsUint16s(coolMulti) { fmt.Println("coolSingle is a uint, and coolMulti is an array of uints") }
Output: coolSingle is a uint, and coolMulti is an array of uints
func (YoMap) IsUint16s ¶
IsUint16s returns a bool indicating whether the value of key s within YoMap is of type []uint16.
Example ¶
// ... see the IsUint16() example ...//
Output:
func (YoMap) IsUint32 ¶
IsUint32 returns a bool indicating whether the value of key s within YoMap is of type uint32.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: uint32(30549577), `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []uint32{0, 53, 78243, 342}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsUint32(coolSingle) && ym.IsUint32s(coolMulti) { fmt.Println("coolSingle is a uint, and coolMulti is an array of uints") }
Output: coolSingle is a uint, and coolMulti is an array of uints
func (YoMap) IsUint32s ¶
IsUint32s returns a bool indicating whether the value of key s within YoMap is of type []uint32.
Example ¶
// ... see the IsUint32() example ...//
Output:
func (YoMap) IsUint64 ¶
IsUint64 returns a bool indicating whether the value of key s within YoMap is of type uint64.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: uint64(3054957437), `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []uint64{0, 53, 78243, 342}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsUint64(coolSingle) && ym.IsUint64s(coolMulti) { fmt.Println("coolSingle is a uint, and coolMulti is an array of uints") }
Output: coolSingle is a uint, and coolMulti is an array of uints
func (YoMap) IsUint64s ¶
IsUint64s returns a bool indicating whether the value of key s within YoMap is of type []uint64.
Example ¶
// ... see the IsUint64() example ...//
Output:
func (YoMap) IsUint8 ¶
IsUint8 returns a bool indicating whether the value of key s within YoMap is of type uint8.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: uint8(30), `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []uint8{0, 53, 254, 142}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsUint8(coolSingle) && ym.IsUint8s(coolMulti) { fmt.Println("coolSingle is a uint, and coolMulti is an array of uints") }
Output: coolSingle is a uint, and coolMulti is an array of uints
func (YoMap) IsUint8s ¶
IsUint8s returns a bool indicating whether the value of key s within YoMap is of type []uint8.
Example ¶
// ... see the IsUint8() example ...//
Output:
func (YoMap) IsUintptr ¶
IsUintptr returns a bool indicating whether the value of key s within YoMap is of type uintptr.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `coolSingle`: uintptr(437853), `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []uintptr{432875, 53234, 18845, 24536}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `coolSingle`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.IsUintptr(coolSingle) && ym.IsUintptrs(coolMulti) { fmt.Println("coolSingle is a uintptr, and coolMulti is an array of uintptrs") }
Output: coolSingle is a uintptr, and coolMulti is an array of uintptrs
func (YoMap) IsUintptrs ¶
IsUintptrs returns a bool indicating whether the value of key s within YoMap is of type []uintptr.
Example ¶
// ... see the IsUintptr() example ...//
Output:
func (YoMap) IsUints ¶
IsUints returns a bool indicating whether the value of key s within YoMap is of type []uint.
Example ¶
// ... see the IsUint() example ...//
Output:
func (YoMap) IsYoMap ¶
IsYoMap returns a bool indicating whether the value of key s within YoMap is of type YoMap.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: []YoMap{ {`test`: `haha`}, {`notfunny`: `true`}, }, }, }, } var coolSingle []string = []string{`firstLevel`, `secondLevel`} var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`} if ym.IsYoMap(coolSingle) && ym.IsYoMaps(coolMulti) { fmt.Println("coolSingle is a yomap, and coolMulti is an array of yomaps") }
Output: coolSingle is a yomap, and coolMulti is an array of yomaps
func (YoMap) IsYoMaps ¶
IsYoMaps returns a bool indicating whether the value of key s within YoMap is of type []YoMap.
Example ¶
// ... see the IsYoMap() example ...//
Output:
func (YoMap) Lacks ¶
Lacks will return a bool indicating whether or not the named key (s) does not exist.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolString`: `this is pretty awesome!`, }, }, }, } var path []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `lameString`} if ym.Lacks(path) { fmt.Println("lameString didn't exist") }
Output: lameString didn't exist
func (YoMap) Len ¶
Len will return an integer which represents the length (number of named entries) for a given instance of YoMap.
Example ¶
ym := YoMap{ `coolString`: true, `coolBytes`: []byte(`bytes`), `coolBool`: true, } fmt.Printf("YoMap is %d entries long", ym.Len())
Output: YoMap is 3 entries long
func (YoMap) NilInInterfaces ¶
NilInInterfaces returns a bool indicating whether the value is present within a given array interfaces.
Example ¶
// ... see ErrorInInterfaces() example, substituting with nil ... //
Output:
func (YoMap) Ready ¶
Ready will return a bool indicating whether the instance of YoMap is initialized (non-nil). Do not confuse "uninitialized" with "empty". A YoMap instance (and maps, for that matter) can have a length of 0 and be non-nil. Use YoMap.Len() if you're interested in the number of entries present within a YoMap instance.
Example ¶
ym := New() if ym.Ready() { fmt.Printf("This YoMap instance is so ready") }
Output: This YoMap instance is so ready
func (YoMap) Reset ¶
func (c YoMap) Reset(s ...interface{})
Reset will traverse all keys within a given instance of YoMap; the YoMap.Delete() method is executed for each key. No checks are done beforehand with regards to "nilness", nor are any warnings raised. This leaves the same "space" allocated, which means that if one reuses this object instance, it is faster than running yomap.New() again.
Example ¶
ym := YoMap{ `coolString`: true, `coolBytes`: []byte(`bytes`), `coolBool`: true, } ym.Reset() fmt.Printf("%d entries remaining in YoMap", ym.Len())
Output: 0 entries remaining in YoMap
func (YoMap) RuneInInterfaces ¶
RuneInInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see the RuneInRunes() example, substituting for type as appropriate ...//
Output:
func (YoMap) RuneInRunes ¶
RuneInRunes returns a bool indicating whether the value is present within a given array of same type.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []rune{'a', 'b', 'c'}, }, }, }, } var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.RuneInRunes(coolMulti, 'c') { fmt.Println("Desired rune found in array of runes") }
Output: Desired rune found in array of runes
func (YoMap) Set ¶
func (c YoMap) Set(s ...interface{})
Set will add the named entry (s) with the value (i) provided. Note this will overwrite anything that already exists by that name.
Example ¶
ym := YoMap{ `coolString`: `true`, `coolBytes`: []byte(`...someBytes...`), `coolBool`: true, } ym.Set([]string{`coolError`}, fmt.Errorf("Coolness limit has been exceeded")) ym.Set([]string{`coolInt`}, 1) length := ym.Len() fmt.Printf("YoMap is %d entries long", length)
Output: YoMap is 5 entries long
func (YoMap) String ¶
func (c YoMap) String(s ...interface{})
String will simply print out the contents in a human-readable fashion; not intended to be parsed.
Example ¶
ym := YoMap{ `coolString`: `true`, `coolBytes`: []byte(`...someBytes...`), `coolBool`: true, } ym.String() // This should print the following to Stdout: //coolString: true (type:string) //coolBytes: [46 46 46 115 111 109 101 66 121 116 101 115 46 46 46] (type:[]uint8) //coolBool: true (type:bool)
Output:
func (YoMap) StringInInterfaces ¶
StringInInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see StringInStrings() example, substituting for type as appropriate ... //
Output:
func (YoMap) StringInStrings ¶
StringInStrings returns a bool indicating whether the value is present within a given array of same type.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolStrings`: []string{`string1`, `string2`, `string3`}, }, }, }, } var coolStrings []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolStrings`} if ym.StringInStrings(coolStrings, `string1`) { fmt.Println("Desired string found in array of strings") }
Output: Desired string found in array of strings
func (YoMap) TypeOf ¶
TypeOf will return the string form of a key's type of value.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolUnknownThing`: 3.14159, }, }, }, } var path []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolUnknownThing`} fmt.Printf("%s", ym.TypeOf(path))
Output: float64
func (YoMap) Uint16InInterfaces ¶
Uint16InInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see UintInUints() example, substituting for type as appropriate ... //
Output:
func (YoMap) Uint16InUint16s ¶
Uint16InUint16s returns a bool indicating whether the value is present within a given array of same type.
Example ¶
// ... see UintInUints() example, substituting for type as appropriate ... //
Output:
func (YoMap) Uint32InInterfaces ¶
Uint32InInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see UintInUints() example, substituting for type as appropriate ... //
Output:
func (YoMap) Uint32InUint32s ¶
Uint32InUint32s returns a bool indicating whether the value is present within a given array of same type.
Example ¶
// ... see UintInUints() example, substituting for type as appropriate ... //
Output:
func (YoMap) Uint64InInterfaces ¶
Uint64InInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see IntInInts() example, substituting for type as appropriate ... //
Output:
func (YoMap) Uint64InUint64s ¶
Uint64InUint64s returns a bool indicating whether the value is present within a given array of same type.
Example ¶
// ... see UintInUints() example, substituting for type as appropriate ... //
Output:
func (YoMap) Uint8InInterfaces ¶
Uint8InInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see UintInUints() example, substituting for type as appropriate ... //
Output:
func (YoMap) Uint8InUint8s ¶
Uint8InUint8s returns a bool indicating whether the value is present within a given array of same type.
Example ¶
// ... see UintInUints() example, substituting for type as appropriate ... //
Output:
func (YoMap) UintInInterfaces ¶
UintInInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
func (YoMap) UintInUints ¶
UintInUints returns a bool indicating whether the value is present within a given array of same type.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolNumbers`: []uint{1, 2, 3, 4}, }, }, }, } var coolNumbers []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolNumbers`} if ym.UintInUints(coolNumbers, uint(4)) { fmt.Println("Desired uint found in array of uints") }
Output: Desired uint found in array of uints
func (YoMap) UintptrInInterfaces ¶
UintptrInInterfaces returns a bool indicating whether the value is present within a given array of interfaces.
Example ¶
// ... see the UintptrInUintptrs() example, substituting for type as appropriate ... //
Output:
func (YoMap) UintptrInUintptrs ¶
UintptrInUintptrs returns a bool indicating whether the value is present within a given array of same type.
Example ¶
ym := YoMap{ `firstLevel`: YoMap{ `secondLevel`: YoMap{ `thirdLevel`: YoMap{ `coolMulti`: []uintptr{432875, 53234, 18845, 24536}, }, }, }, } var coolMulti []string = []string{`firstLevel`, `secondLevel`, `thirdLevel`, `coolMulti`} if ym.UintptrInUintptrs(coolMulti, uintptr(53234)) { fmt.Println("Desired uintptr found in array of uintptrs") }
Output: Desired uintptr found in array of uintptrs