beats: Index | Files

package mapstrstr

import ""

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:

	"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"),

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


Package Files


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 622 packages. Updated 2020-03-27. Refresh now. Tools for package owners.