attributes

package
v0.0.4-memsql Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(resource map[string]interface{}, key string, value interface{}) error

Add stores the given key and value, returns an error if the key in use.

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

func Contains(id string, a map[string]interface{}) (interface{}, bool)

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 Depth

func Depth(resource map[string]interface{}) int

Depth returns the amount of nested maps.

func EnsureComplexAttribute

func EnsureComplexAttribute(resource map[string]interface{}, key string) map[string]interface{}

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 Exists

func Exists(resource map[string]interface{}, key string) bool

Exists checks whether the key exists in the map.

func GetBool

func GetBool(id string, a map[string]interface{}) (bool, error)

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

func GetFloat(id string, a map[string]interface{}) (float64, error)

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

func GetFloatAsInt(id string, a map[string]interface{}) (int, error)

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

func GetMap(id string, a map[string]interface{}) (map[string]interface{}, error)

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

func GetString(id string, a map[string]interface{}) (string, error)

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

func GetStringInSubMap(mID, sID string, a map[string]interface{}) (string, error)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL