Documentation ¶
Index ¶
- func IsDynMapConvertable(value interface{}) bool
- func Less(val1, val2 interface{}) bool
- func MustBool(value interface{}, def bool) bool
- func MustInt(value interface{}, def int) int
- func MustString(value interface{}, def string) string
- func PrettyJSON(obj interface{}) string
- func Sort(vals []DynMap, sortCol string)
- func ToArray(value interface{}) ([]interface{}, bool)
- func ToBool(value interface{}) (bool, error)
- func ToFloat64(value interface{}) (f float64, err error)
- func ToInt(value interface{}) (int, error)
- func ToInt64(value interface{}) (i int64, err error)
- func ToMap(value interface{}) (map[string]interface{}, bool)
- func ToSortVal(value interface{}) (interface{}, int)
- func ToString(value interface{}) string
- func ToTime(value interface{}) (tm time.Time, err error)
- type DynMap
- func (this DynMap) AddToSlice(key string, mp ...interface{}) error
- func (this DynMap) AddToSliceWithDot(key string, mp ...interface{}) error
- func (dm *DynMap) Clone() *DynMap
- func (this DynMap) Contains(key string) bool
- func (this DynMap) ContainsAll(keys ...string) bool
- func (this DynMap) ContainsDynMap(key string) bool
- func (this DynMap) ContainsString(key string) bool
- func (this *DynMap) ConvertTo(val interface{}) error
- func (this *DynMap) Exists(key string) bool
- func (this *DynMap) Flatten() map[string]interface{}
- func (this *DynMap) Get(key string) (interface{}, bool)
- func (this DynMap) GetBool(key string) (bool, bool)
- func (this DynMap) GetDynMap(key string) (*DynMap, bool)
- func (this DynMap) GetDynMapSlice(key string) ([]*DynMap, bool)
- func (this DynMap) GetFloat64(key string) (float64, bool)
- func (this DynMap) GetInt(key string) (int, bool)
- func (this DynMap) GetInt64(key string) (int64, bool)
- func (this DynMap) GetIntSlice(key string) ([]int, bool)
- func (this DynMap) GetIntSliceSplit(key, delim string) ([]int, bool)
- func (this DynMap) GetString(key string) (string, bool)
- func (this DynMap) GetStringSlice(key string) ([]string, bool)
- func (this DynMap) GetStringSliceSplit(key, delim string) ([]string, bool)
- func (this DynMap) GetTime(key string) (time.Time, bool)
- func (this *DynMap) IsEmpty() bool
- func (this *DynMap) Length() int
- func (this DynMap) MarshalJSON() ([]byte, error)
- func (this *DynMap) MarshalUrl() (string, error)
- func (this *DynMap) Merge(mp *DynMap) *DynMap
- func (this *DynMap) Must(key string, def interface{}) interface{}
- func (this DynMap) MustBool(key string, def bool) bool
- func (this DynMap) MustDynMap(key string, def *DynMap) *DynMap
- func (this DynMap) MustDynMapSlice(key string, def []*DynMap) []*DynMap
- func (this DynMap) MustFloat64(key string, def float64) float64
- func (this DynMap) MustInt(key string, def int) int
- func (this DynMap) MustInt64(key string, def int64) int64
- func (this DynMap) MustString(key string, def string) string
- func (this DynMap) MustStringSlice(key string, def []string) []string
- func (this DynMap) MustTime(key string, def time.Time) time.Time
- func (this *DynMap) Put(key string, value interface{})
- func (this *DynMap) PutAll(mp interface{}) bool
- func (this *DynMap) PutIfAbsent(key string, value interface{}) (interface{}, bool)
- func (this *DynMap) PutIfAbsentWithDot(key string, value interface{}) (interface{}, bool)
- func (this *DynMap) PutWithDot(key string, value interface{}) error
- func (this *DynMap) Remove(key string) (interface{}, bool)
- func (dm *DynMap) RemoveAll(key ...string)
- func (this *DynMap) ToDynMap() *DynMap
- func (this DynMap) ToJSON() string
- func (this *DynMap) ToMap() map[string]interface{}
- func (dm *DynMap) UnFlatten() (*DynMap, error)
- func (this *DynMap) UnmarshalJSON(bytes []byte) error
- func (this *DynMap) UnmarshalUrl(urlstring string) error
- func (this *DynMap) UnmarshalUrlValues(values url.Values) error
- type DynMapSlice
- type DynMaper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsDynMapConvertable ¶
func IsDynMapConvertable(value interface{}) bool
Returns true if the given value is a map, dynmap, DynMaper or pointer of one of those types
func MustString ¶
func PrettyJSON ¶
func PrettyJSON(obj interface{}) string
attempts to convert the passed in object to a dynmap then JSON, ignoring any errors
func ToArray ¶
func ToArray(value interface{}) ([]interface{}, bool)
convert the object into an array if possible
func ToSortVal ¶
func ToSortVal(value interface{}) (interface{}, int)
cleans up to one of the types we know about, attempting to convert: the conversion here is not as aggressive as the above methods. Will deference any pointers but strings will not be attempted to be parsed dynmap time int64 bool string
integer returned is the sort order, so bool < int < string < time < map
Types ¶
type DynMap ¶
type DynMap struct {
Map map[string]interface{} `bson:",inline"`
}
Dont make this a map type, since we want the option of extending this and adding members.
func (DynMap) AddToSlice ¶
Adds the item to a slice
func (DynMap) AddToSliceWithDot ¶
Adds the item to a slice
func (DynMap) ContainsAll ¶
func (DynMap) ContainsDynMap ¶
func (DynMap) ContainsString ¶
func (*DynMap) ConvertTo ¶
Attempts to fill the given struct with the values contained in this dynmap.
func (*DynMap) Flatten ¶
flattens this dynmap into a one level map where all keys use the dot operator, and values are not maps (primitives or objects) arrays and slices are indexed by integer for instance key1: ["v1", "v2"] => key1.0:v1, key1.1:v2 Note that the slice syntax is not supported yet by PutWithDot so flattened keys cannot be automatically used to recreate the nested map (todo)
func (*DynMap) Get ¶
Get's the value. will honor the dot operator if needed. key = 'map.map2' will first attempt to matche the literal key 'map.map2' if no value is present it will look for a sub map at key 'map'
func (DynMap) GetDynMap ¶
Gets a dynmap from the requested. This will update the value in the map if the value was not already a dynmap.
func (DynMap) GetDynMapSlice ¶
gets a slice of dynmaps
func (DynMap) GetInt64 ¶
Gets the value at the specified key as an int64. returns -1,false if value not available or is not convertable
func (DynMap) GetIntSlice ¶
Returns a slice of ints
func (DynMap) GetIntSliceSplit ¶
gets a slice of ints. if the value is a string it will split by the requested delimiter
func (DynMap) GetStringSlice ¶
Returns a slice of strings
func (DynMap) GetStringSliceSplit ¶
gets a slice of strings. if the value is a string it will split by the requested delimiter
func (DynMap) MarshalJSON ¶
func (*DynMap) MarshalUrl ¶
encodes this map into a url encoded string. maps are encoded in the rails style (key[key2][key2]=value) TODO: we should sort the keynames so ordering is consistent and then this can be used a cache key
func (*DynMap) Merge ¶
recursively merges the requested dynmap into the current dynmap returns self in order to support chaining.
func (DynMap) MustDynMapSlice ¶
func (DynMap) MustString ¶
gets a string. if string is not available in the map, then the default is returned
func (DynMap) MustStringSlice ¶
func (*DynMap) PutAll ¶
puts all the values from the passed in map into this dynmap the passed in map must be convertable to a DynMap via ToDynMap. returns false if the passed value is not convertable to dynmap
func (*DynMap) PutIfAbsent ¶
Puts the value into the map if and only if no value exists at the specified key. This does not honor the dot operator on insert.
func (*DynMap) PutIfAbsentWithDot ¶
Same as PutIfAbsent but honors the dot operator
func (*DynMap) PutWithDot ¶
puts the value into the map, honoring the dot operator. so PutWithDot("map1.map2.value", 100) would result in:
{ map1 : { map2 : { value: 100 }}
}
func (DynMap) ToJSON ¶
converts to indented json, throws away any errors this is useful for logging purposes. MarshalJSON should be used for most uses.
func (*DynMap) UnFlatten ¶
Takes any dot operator keys and makes nested maps returns a new DynMap instance
func (*DynMap) UnmarshalJSON ¶
func (*DynMap) UnmarshalUrl ¶
Unmarshals a url encoded string. will also parse rails style maps in the form key[key1][key2]=val
type DynMapSlice ¶
type DynMapSlice struct {
// contains filtered or unexported fields
}
func NewDynMapSlice ¶
func NewDynMapSlice(vals []DynMap, sortCol string) DynMapSlice
func (DynMapSlice) Len ¶
func (dms DynMapSlice) Len() int
func (DynMapSlice) Less ¶
func (dms DynMapSlice) Less(i, j int) bool
func (DynMapSlice) Swap ¶
func (dms DynMapSlice) Swap(i, j int)