Documentation
¶
Overview ¶
Package mapstriface contains utilities for transforming map[string]interface{} objects into metricbeat events. For example, given this input object:
input := map[string]interface{}{
"testString": "hello",
"testInt": 42,
"testIntFromFloat": 42.0,
"testIntFromInt64": int64(42),
"testBool": true,
"testObj": map[string]interface{}{
"testObjString": "hello, object",
},
"testNonNestedObj": "hello from top level",
}
And the requirement to transform it into this one:
common.MapStr{
"test_string": "hello",
"test_int": int64(42),
"test_int_from_float": int64(42),
"test_int_from_int64": int64(42),
"test_bool": true,
"test_time": common.Time(ts),
"test_obj_1": common.MapStr{
"test": "hello from top level",
},
"test_obj_2": common.MapStr{
"test": "hello, object",
},
}
It can be done with the following code:
schema := s.Schema{
"test_string": Str("testString"),
"test_int": Int("testInt"),
"test_int_from_float": Int("testIntFromFloat"),
"test_int_from_int64": Int("testIntFromInt64"),
"test_bool": Bool("testBool"),
"test_time": Time("testTime"),
"test_obj_1": s.Object{
"test": Str("testNonNestedObj"),
},
"test_obj_2": Dict("testObj", s.Schema{
"test": Str("testObjString"),
}),
}
output := schema.Apply(input)
Note that this allows for converting, renaming, and restructuring the data.
Index ¶
- func Bool(key string, opts ...schema.SchemaOption) schema.Conv
- func Ifc(key string, opts ...schema.SchemaOption) schema.Conv
- func Int(key string, opts ...schema.SchemaOption) schema.Conv
- func Str(key string, opts ...schema.SchemaOption) schema.Conv
- func StrFromNum(key string, opts ...schema.SchemaOption) schema.Conv
- func Time(key string, opts ...schema.SchemaOption) schema.Conv
- type ConvMap
- type DictSchemaOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
func Bool(key string, opts ...schema.SchemaOption) schema.Conv
Bool creates a Conv object for converting booleans.
func Ifc ¶
func Ifc(key string, opts ...schema.SchemaOption) schema.Conv
Ifc creates a schema.Conv object for converting the given data to interface.
func Int ¶
func Int(key string, opts ...schema.SchemaOption) schema.Conv
Int creates a Conv object for converting integers. Acceptable input types are int64, int, and float64.
func Str ¶
func Str(key string, opts ...schema.SchemaOption) schema.Conv
Str creates a schema.Conv object for converting strings.
Types ¶
Source Files
¶
- mapstriface.go
Click to show internal directories.
Click to hide internal directories.