beats: github.com/elastic/beats/libbeat/common/schema/mapstrstr Index | Files

package mapstrstr

import "github.com/elastic/beats/libbeat/common/schema/mapstrstr"

Package mapstrstr contains utilities for transforming map[string]string objects into metricbeat events. For example, given this input object:

input := map[string]interface{}{
	"testString":     "hello",
	"testInt":        "42",
	"testBool":       "true",
	"testFloat":      "42.1",
	"testObjString":  "hello, object",
}

And the requirement to transform it into this one:

common.MapStr{
	"test_string": "hello",
	"test_int":    int64(42),
	"test_bool":   true,
	"test_float":  42.1,
	"test_obj": common.MapStr{
		"test_obj_string": "hello, object",
	},
}

It can be done with the following code:

schema := s.Schema{
	"test_string": Str("testString"),
	"test_int":    Int("testInt"),
	"test_bool":   Bool("testBool"),
	"test_float":  Float("testFloat"),
	"test_obj": s.Object{
		"test_obj_string": Str("testObjString"),
	},
}
schema.Apply(input)

Note that this allows parsing, renaming of fields and restructuring the result object.

Index

Package Files

mapstrstr.go

func Bool Uses

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

Bool creates a Conv object for parsing booleans

func Float Uses

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

Float creates a Conv object for parsing floats

func Int Uses

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

Int creates a Conv object for parsing integers

func Str Uses

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

Str creates a schema.Conv object for parsing strings

func Time Uses

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

Time creates a schema.Conv object for parsing timestamps. Unlike the other functions, Time receives a `layout` parameter which defines the time.Time layout to use for parsing.

Package mapstrstr imports 5 packages (graph) and is imported by 194 packages. Updated 2018-07-13. Refresh now. Tools for package owners.