mapstriface

package
v5.0.0-alpha5+incompat... Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2016 License: Apache-2.0 Imports: 5 Imported by: 0

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

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 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

func Time

func Time(key string, opts ...schema.SchemaOption) schema.Conv

Time creates a Conv object for converting Time objects.

Types

type ConvMap

type ConvMap struct {
	Key    string        // The key in the data map
	Schema schema.Schema // The schema describing how to convert the sub-map
}

func Dict

func Dict(key string, s schema.Schema) ConvMap

func (ConvMap) Map

func (convMap ConvMap) Map(key string, event common.MapStr, data map[string]interface{})

Map drills down in the data dictionary by using the key

Jump to

Keyboard shortcuts

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