mapstrstr

package
v6.1.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2018 License: Apache-2.0 Imports: 5 Imported by: 2,111

Documentation

Overview

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

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

func Float

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

Float creates a Conv object for parsing floats

func Int

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

Int creates a Conv object for parsing integers

func Str

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

Str creates a schema.Conv object for parsing strings

func Time

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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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