Documentation
¶
Index ¶
- func Add(resource map[string]interface{}, key string, value interface{}) error
- func AddEmptyComplexAttribute(resource map[string]interface{}, key string) (map[string]interface{}, error)
- func AppendComplexMultiValuedAttribute(resource map[string]interface{}, key string, value map[string]interface{}) error
- func AppendMultiValuedAttribute(resource map[string]interface{}, key string, value interface{}) error
- func Contains(id string, a map[string]interface{}) (interface{}, bool)
- func Depth(resource map[string]interface{}) int
- func EnsureComplexAttribute(resource map[string]interface{}, key string) map[string]interface{}
- func EnsureComplexMultiValuedAttribute(resource map[string]interface{}, key string, length int) []map[string]interface{}
- func EnsureMultiValuedAttribute(resource map[string]interface{}, key string, length int) []interface{}
- func Exists(resource map[string]interface{}, key string) bool
- func GetBool(id string, a map[string]interface{}) (bool, error)
- func GetFloat(id string, a map[string]interface{}) (float64, error)
- func GetFloatAsInt(id string, a map[string]interface{}) (int, error)
- func GetMap(id string, a map[string]interface{}) (map[string]interface{}, error)
- func GetString(id string, a map[string]interface{}) (string, error)
- func GetStringInSubMap(mID, sID string, a map[string]interface{}) (string, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddEmptyComplexAttribute ¶
func AddEmptyComplexAttribute(resource map[string]interface{}, key string) (map[string]interface{}, error)
AddEmptyComplexAttribute creates a new map with given key, returns an error if the key in use.
func AppendComplexMultiValuedAttribute ¶
func AppendComplexMultiValuedAttribute(resource map[string]interface{}, key string, value map[string]interface{}) error
AppendComplexMultiValuedAttribute adds given complex value to the complex multi valued attribute with the given key. Tries to fill up nil values before appending. Returns an error IF: - the slice is not present. - it is not a slice of maps.
func AppendMultiValuedAttribute ¶
func AppendMultiValuedAttribute(resource map[string]interface{}, key string, value interface{}) error
AppendMultiValuedAttribute adds given value to the multi valued attribute with the given key. Tries to fill up nil values before appending. Returns an error IF: - the slice is not present. - it is not a slice. - the value type does not match the type of the content.
func Contains ¶
Contains checks whether the given map contains the id. This check is case insensitive!
Example ¶
package main import ( "fmt" "github.com/memsql/scimtools/attributes" ) func main() { attrs := map[string]interface{}{ "x": 0, } fmt.Println(attributes.Contains("x", attrs)) fmt.Println(attributes.Contains("X", attrs)) fmt.Println(attributes.Contains("y", attrs)) }
Output: 0 true 0 true <nil> false
func EnsureComplexAttribute ¶
EnsureComplexAttribute gets the complex attribute based on the given key. IF not present -> it creates an empty map. IF not a map -> it overwrites it with an empty map.
func EnsureComplexMultiValuedAttribute ¶
func EnsureComplexMultiValuedAttribute(resource map[string]interface{}, key string, length int) []map[string]interface{}
EnsureComplexMultiValuedAttribute gets the complex multi valued attribute based on the given key. Makes sure the size is at least the given length (by appending empty maps if smaller). IF not present -> it creates an empty slice of empty maps of given length. IF not a slice -> it overwrites it with an empty slice of empty maps of given length.
func EnsureMultiValuedAttribute ¶
func EnsureMultiValuedAttribute(resource map[string]interface{}, key string, length int) []interface{}
EnsureMultiValuedAttribute gets the multi valued attribute based on the given key. Makes sure the size is at least the given length (by appending nil if smaller). IF not present -> it creates an empty slice of given length. IF not a map -> it overwrites it with an empty slice of given length.
func GetBool ¶
GetBool searches the given map for a boolean that matches the given id.
Example ¶
package main import ( "fmt" "github.com/memsql/scimtools/attributes" ) func main() { attrs := map[string]interface{}{ "x": true, "y": 0, } fmt.Println(attributes.GetBool("x", attrs)) fmt.Println(attributes.GetBool("y", attrs)) fmt.Println(attributes.GetBool("z", attrs)) }
Output: true <nil> false attribute "y" is not a bool false could not find "z" in attributes
func GetFloat ¶
GetFloat searches the given map for a float that matches the given id.
Example ¶
package main import ( "fmt" "github.com/memsql/scimtools/attributes" ) func main() { attrs := map[string]interface{}{ "x": 0.1, "y": false, } fmt.Println(attributes.GetFloat("x", attrs)) fmt.Println(attributes.GetFloat("y", attrs)) fmt.Println(attributes.GetFloat("z", attrs)) }
Output: 0.1 <nil> 0 attribute "y" is not a float64 0 could not find "z" in attributes
func GetFloatAsInt ¶
GetFloatAsInt searches the given map for a float that matches the given id and converts it to an int if possible.
Example ¶
package main import ( "fmt" "github.com/memsql/scimtools/attributes" ) func main() { attrs := map[string]interface{}{ "x": float64(1), "y": 0.1, } fmt.Println(attributes.GetFloatAsInt("x", attrs)) fmt.Println(attributes.GetFloatAsInt("y", attrs)) fmt.Println(attributes.GetFloatAsInt("z", attrs)) }
Output: 1 <nil> 0 attribute "y" is not a int 0 could not find "z" in attributes
func GetMap ¶
GetMap searches the given map for a map that matches the given id.
Example ¶
package main import ( "fmt" "github.com/memsql/scimtools/attributes" ) func main() { attrs := map[string]interface{}{ "x": map[string]interface{}{ "z": true, }, "y": 0, } fmt.Println(attributes.GetMap("x", attrs)) fmt.Println(attributes.GetMap("y", attrs)) fmt.Println(attributes.GetMap("z", attrs)) }
Output: map[z:true] <nil> map[] attribute "y" is not a map[string]interface{} map[] could not find "z" in attributes
func GetString ¶
GetString searches the given map for a string that matches the given id.
Example ¶
package main import ( "fmt" "github.com/memsql/scimtools/attributes" ) func main() { attrs := map[string]interface{}{ "x": "x", "y": 0, } fmt.Println(attributes.GetString("x", attrs)) fmt.Println(attributes.GetString("y", attrs)) fmt.Println(attributes.GetString("z", attrs)) }
Output: x <nil> attribute "y" is not a string could not find "z" in attributes
func GetStringInSubMap ¶
GetStringInSubMap searches the given map for a string with key sID in the map matching the given mID.
Example ¶
package main import ( "fmt" "github.com/memsql/scimtools/attributes" ) func main() { attrs := map[string]interface{}{ "x": map[string]interface{}{ "x": "x", "y": 0, }, } fmt.Println(attributes.GetStringInSubMap("x", "x", attrs)) fmt.Println(attributes.GetStringInSubMap("x", "y", attrs)) fmt.Println(attributes.GetStringInSubMap("x", "z", attrs)) fmt.Println(attributes.GetStringInSubMap("y", "x", attrs)) }
Output: x <nil> attribute "y" is not a string could not find "z" in attributes could not find "y" in attributes
Types ¶
This section is empty.