コード例 #1
0
ファイル: mapstrstr.go プロジェクト: YaSuenag/hsbeat
// 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.
func Time(layout, key string, opts ...schema.SchemaOption) schema.Conv {
	return schema.SetOptions(schema.Conv{
		Key: key,
		Func: func(key string, data map[string]interface{}) (interface{}, error) {
			str, err := getString(key, data)
			if err != nil {
				return false, err
			}

			value, err := time.Parse(layout, str)
			if err != nil {
				return 0, fmt.Errorf("Error converting param to time.Time: %s. Original: %s", key, str)
			}

			return common.Time(value), nil
		},
	}, opts)
}
コード例 #2
0
ファイル: mapstriface.go プロジェクト: ruflin/beats
// Time creates a Conv object for converting Time objects.
func Time(key string, opts ...schema.SchemaOption) schema.Conv {
	return schema.SetOptions(schema.Conv{Key: key, Func: toTime}, opts)
}
コード例 #3
0
ファイル: mapstriface.go プロジェクト: ruflin/beats
// Int creates a Conv object for converting integers. Acceptable input
// types are int64, int, and float64.
func Int(key string, opts ...schema.SchemaOption) schema.Conv {
	return schema.SetOptions(schema.Conv{Key: key, Func: toInteger}, opts)
}
コード例 #4
0
ファイル: mapstriface.go プロジェクト: ruflin/beats
// Bool creates a Conv object for converting booleans.
func Bool(key string, opts ...schema.SchemaOption) schema.Conv {
	return schema.SetOptions(schema.Conv{Key: key, Func: toBool}, opts)
}
コード例 #5
0
ファイル: mapstriface.go プロジェクト: ruflin/beats
// Str creates a schema.Conv object for converting strings.
func Str(key string, opts ...schema.SchemaOption) schema.Conv {
	return schema.SetOptions(schema.Conv{Key: key, Func: toStr}, opts)
}
コード例 #6
0
ファイル: mapstrstr.go プロジェクト: ChongFeng/beats
// Float creates a Conv object for parsing floats
func Float(key string, opts ...schema.SchemaOption) schema.Conv {
	return schema.SetOptions(schema.Conv{Key: key, Func: toFloat}, opts)
}