converters

package
v0.77.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package converters provides data.FieldConverters commonly used by plugins.

Index

Constants

This section is empty.

Variables

View Source
var AnyToNullableString = data.FieldConverter{
	OutputFieldType: data.FieldTypeNullableString,
	Converter: func(v interface{}) (interface{}, error) {
		var str *string
		if v != nil {
			s := fmt.Sprintf("%v", v)
			str = &s
		}
		return str, nil
	},
}

AnyToNullableString converts any non-nil value into a *string. If the the input value is nil the output value is *string typed nil.

View Source
var AnyToString = data.FieldConverter{
	OutputFieldType: data.FieldTypeString,
	Converter: func(v interface{}) (interface{}, error) {
		return fmt.Sprintf("%v", v), nil
	},
}

AnyToString converts any value into a string.

View Source
var BoolNOOP = data.FieldConverter{
	OutputFieldType: data.FieldTypeBool,
}

BoolNOOP is a data.FieldConverter that performs no conversion. It should be used when the input type is an bool and the Field's type is also an bool. The conversion will panic if the the input type does not match the Field type.

View Source
var BoolToNullableBool = data.FieldConverter{
	OutputFieldType: data.FieldTypeNullableBool,
	Converter: func(v interface{}) (interface{}, error) {
		var ptr *bool
		if v == nil {
			return ptr, nil
		}
		val, ok := v.(bool)
		if !ok {
			return ptr, toConversionError("bool", v)
		}
		ptr = &val
		return ptr, nil
	},
}

BoolToNullableBool returns an error if the input is not a bool.

View Source
var Boolean = data.FieldConverter{
	OutputFieldType: data.FieldTypeBool,
	Converter: func(v interface{}) (interface{}, error) {
		fV, ok := v.(bool)
		if !ok {
			return nil, toConversionError("bool", v)
		}
		return fV, nil
	},
}

Boolean returns an error if the input is not a bool.

View Source
var Float64EpochMillisToTime = data.FieldConverter{
	OutputFieldType: data.FieldTypeTime,
	Converter: func(v interface{}) (interface{}, error) {
		fV, ok := v.(float64)
		if !ok {
			return nil, toConversionError("float64", v)
		}
		return time.Unix(0, int64(fV)*int64(time.Millisecond)).UTC(), nil
	},
}

Float64EpochMillisToTime convert numeric milliseconds to time.Time

View Source
var Float64EpochSecondsToTime = data.FieldConverter{
	OutputFieldType: data.FieldTypeTime,
	Converter: func(v interface{}) (interface{}, error) {
		fV, ok := v.(float64)
		if !ok {
			return nil, toConversionError("float64", v)
		}
		return time.Unix(int64(fV), 0).UTC(), nil
	},
}

Float64EpochSecondsToTime converts a numeric seconds to time.Time.

View Source
var Float64NOOP = data.FieldConverter{
	OutputFieldType: data.FieldTypeFloat64,
}

Float64NOOP is a data.FieldConverter that performs no conversion. It should be used when the input type is an float64 and the Field's type is also an float64. The conversion will panic if the the input type does not match the Field type.

View Source
var Float64ToNullableFloat64 = data.FieldConverter{
	OutputFieldType: data.FieldTypeNullableFloat64,
	Converter: func(v interface{}) (interface{}, error) {
		var ptr *float64
		if v == nil {
			return ptr, nil
		}
		val, ok := v.(float64)
		if !ok {
			return ptr, toConversionError("float64", v)
		}
		ptr = &val
		return ptr, nil
	},
}

Float64ToNullableFloat64 returns an error if the input is not a float64.

View Source
var Int64NOOP = data.FieldConverter{
	OutputFieldType: data.FieldTypeInt64,
}

Int64NOOP is a data.FieldConverter that performs no conversion. It should be used when the input type is an int64 and the Field's type is also an int64. The conversion will panic if the the input type does not match the Field type.

View Source
var Int64ToNullableInt64 = data.FieldConverter{
	OutputFieldType: data.FieldTypeNullableInt64,
	Converter: func(v interface{}) (interface{}, error) {
		var ptr *int64
		if v == nil {
			return ptr, nil
		}
		val, ok := v.(int64)
		if !ok {
			return ptr, toConversionError("int64", v)
		}
		ptr = &val
		return ptr, nil
	},
}

Int64ToNullableInt64 returns an error if the input is not an int64.

View Source
var StringNOOP = data.FieldConverter{
	OutputFieldType: data.FieldTypeString,
}

StringNOOP is a data.FieldConverter that performs no conversion. It should be used when the input type is an int64 and the Field's type is also an string. The conversion will panic if the the input type does not match the Field type.

View Source
var StringToNullableFloat64 = data.FieldConverter{
	OutputFieldType: data.FieldTypeNullableFloat64,
	Converter: func(v interface{}) (interface{}, error) {
		var ptr *float64
		if v == nil {
			return ptr, nil
		}
		val, ok := v.(string)
		if !ok {
			return ptr, toConversionError("string", v)
		}
		fV, err := strconv.ParseFloat(val, 64)
		ptr = &fV
		return ptr, err
	},
}

StringToNullableFloat64 parses a float64 value from a string.

View Source
var Uint64ToNullableUInt64 = data.FieldConverter{
	OutputFieldType: data.FieldTypeNullableUint64,
	Converter: func(v interface{}) (interface{}, error) {
		var ptr *uint64
		if v == nil {
			return ptr, nil
		}
		val, ok := v.(uint64)
		if !ok {
			return ptr, toConversionError("uint64", v)
		}
		ptr = &val
		return ptr, nil
	},
}

Uint64ToNullableUInt64 returns an error if the input is not a uint64.

Functions

func RFC3339StringToNullableTime

func RFC3339StringToNullableTime(s string) (*time.Time, error)

RFC3339StringToNullableTime convert a string with RFC3339 to a *time.Time object.

Types

This section is empty.

Jump to

Keyboard shortcuts

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