datatype

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2017 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package datatype contains necessary logic to sanitise a JSON object coming from a reader. This package is subjected to change.

Index

Constants

View Source
const (
	// BYTE amount is the same as is read.
	BYTE = 1.0
	// KILOBYTE divides the amount to kilobytes to show smaller value.
	KILOBYTE = 1024 * BYTE
	// MEGABYTE divides the amount to megabytes to show smaller value.
	MEGABYTE = 1024 * KILOBYTE
)

Variables

View Source
var ErrUnidentifiedJason = errors.New("unidentified jason value")

ErrUnidentifiedJason is an error when the value is not identified. It happens when the value is not a string or a float64 types, or the container ends up empty.

View Source
var TimeStampFormat = "2006-01-02T15:04:05.999999-07:00"

TimeStampFormat specifies the format that all timestamps should be formatted with.

Functions

This section is empty.

Types

type ByteType

type ByteType struct {
	Key   string
	Value float64
}

ByteType represents a pair of key values in which the value represents bytes. It converts the value to MB.

func (ByteType) Bytes

func (b ByteType) Bytes() []byte

Bytes returns the byte slice representation of the type. It turns the byte into Megabyte.

func (ByteType) Equal

func (b ByteType) Equal(other DataType) bool

Equal compares both keys and values and returns true if they are equal.

type Container

type Container struct {
	// Err value is set during container creation.
	Err error
	// contains filtered or unexported fields
}

Container satisfies the DataContainer and error interfaces.

func New

func New(list []DataType) *Container

New returns a new container and populates it with the given list.

func (*Container) Add

func (c *Container) Add(d ...DataType)

Add adds d to the list. You can pass it as many items you need to.

func (*Container) Bytes

func (c *Container) Bytes(timestamp time.Time) []byte

Bytes prepends a timestamp pair and value to the list, and generates a json object suitable for recording into a document store.

func (*Container) Error

func (c *Container) Error() error

Error returns the error message.

func (*Container) Len

func (c *Container) Len() int

Len returns the length of the data.

func (*Container) List

func (c *Container) List() []DataType

List returns the data. The error is not provided here, please check the Err value.

type DataContainer

type DataContainer interface {
	// List returns the list. You should not update this list as it is a shared
	// list and anyone can read from it. If you append to this list, there is a
	// chance you are not referring to the same underlying array in memory.
	List() []DataType

	// Len returns the length of the container.
	Len() int

	// Bytes returns the []byte representation of the container by collecting
	// all []byte values of its contents.
	Bytes(timestamp time.Time) []byte

	// Returns the Err value.
	Error() error
}

DataContainer is an interface for holding a list of DataType. I'm aware of the container/list package, which is awesome, but I needed a simple interface to do this job.

func JobResultDataTypes

func JobResultDataTypes(b []byte, mapper Mapper) DataContainer

JobResultDataTypes generates a list of DataType and puts them inside the DataContainer. It returns errors if unmarshaling is unsuccessful or ErrUnidentifiedJason when the container ends up empty.

type DataType

type DataType interface {
	// Bytes returns the []byte representation of the value.
	// It includes both Key and Value.
	Bytes() []byte

	// Equal compares the current object to the other returns true if they have
	// equal values. The value comparison is not ordered.
	Equal(other DataType) bool
}

DataType represents a single paired data. The key of the json value is mapped to Key, and the value is to Value.

type FloatListType

type FloatListType struct {
	Key   string
	Value []float64
}

FloatListType represents a pair of key values that the value is a list of floats.

func (FloatListType) Bytes

func (fl FloatListType) Bytes() []byte

Bytes returns the byte slice representation of the type.

func (FloatListType) Equal

func (fl FloatListType) Equal(other DataType) bool

Equal compares both keys and all values and returns true if they are equal. The values are checked in an unordered fashion.

type FloatType

type FloatType struct {
	Key   string
	Value float64
}

FloatType represents a pair of key values that the value is a float64.

func (FloatType) Bytes

func (f FloatType) Bytes() []byte

Bytes returns the byte slice representation of the type.

func (FloatType) Equal

func (f FloatType) Equal(other DataType) bool

Equal compares both keys and values and returns true if they are equal.

type GCListType

type GCListType struct {
	Key   string
	Value []uint64
}

GCListType represents a pair of key values of GC list info.

func (GCListType) Bytes

func (flt GCListType) Bytes() []byte

Bytes returns the byte slice representation of the type.

func (GCListType) Equal

func (flt GCListType) Equal(other DataType) bool

Equal is not implemented. You should iterate and check yourself. Equal compares both keys and values and returns true if they are equal.

type KiloByteType

type KiloByteType struct {
	Key   string
	Value float64
}

KiloByteType represents a pair of key values in which the value represents bytes. It converts the value to KB.

func (KiloByteType) Bytes

func (k KiloByteType) Bytes() []byte

Bytes returns the byte slice representation of the type.

func (KiloByteType) Equal

func (k KiloByteType) Equal(other DataType) bool

Equal compares both keys and values and returns true if they are equal.

type MapConvert

type MapConvert struct {
	// contains filtered or unexported fields
}

MapConvert can produce output from GC string list and memory type input.

func DefaultMapper

func DefaultMapper() *MapConvert

DefaultMapper returns a MapConvert object that is populated by the default mappings. The data is hard coded in the program, but you can provide your mapping file in your configuration file.

func MapsFromViper

func MapsFromViper(v *viper.Viper) *MapConvert

MapsFromViper reads from the map file and produces functions for conversion used in type decoder. It first reads from the default settings defined in the maps.yml in the same folder, then overrides with the user specified mappings.

func (*MapConvert) Copy

func (m *MapConvert) Copy() Mapper

Copy returns a new copy of the Mapper.

func (*MapConvert) Values

func (m *MapConvert) Values(prefix string, values map[string]*jason.Value) []DataType

Values returns a slice of DataTypes based on the given name/value inputs. It flattens the float list values, therefore you will get multiple values per input. If the name is found in memory_bytes map, it will return one of those, otherwise it will return a FloatType or StringType if can convert. It will return nil if the value is not one of above.

type MapConvertMock

type MapConvertMock struct {
	GCTypes     []string
	MemoryTypes map[string]MemTypeMock
	ValuesFunc  func(prefix string, values map[string]*jason.Value) []DataType

	DefaultCovertor Mapper
	// contains filtered or unexported fields
}

MapConvertMock is the mocked version of MapConvert.

func (*MapConvertMock) Copy

func (m *MapConvertMock) Copy() Mapper

Copy returns a new copy of the Mapper.

func (*MapConvertMock) Values

func (m *MapConvertMock) Values(prefix string, values map[string]*jason.Value) []DataType

Values calls the ValuesFunc if exists, otherwise returns nil.

type Mapper

type Mapper interface {
	// Values closes the channel once all input has been exhausted.
	Values(prefix string, values map[string]*jason.Value) []DataType

	// Copy returns a new copy of the Mapper.
	// You should always copy the mapper if you are using it concurrently.
	Copy() Mapper
}

Mapper generates DataTypes based on the given name/value inputs.

type MegaByteType

type MegaByteType struct {
	Key   string
	Value float64
}

MegaByteType represents a pair of key values in which the value represents bytes. It converts the value to MB.

func (MegaByteType) Bytes

func (m MegaByteType) Bytes() []byte

Bytes returns the byte slice representation of the type.

func (MegaByteType) Equal

func (m MegaByteType) Equal(other DataType) bool

Equal compares both keys and values and returns true if they are equal.

type MemTypeMock

type MemTypeMock struct {
	// contains filtered or unexported fields
}

MemTypeMock is the mocked version of memType.

func (MemTypeMock) IsByte

func (m MemTypeMock) IsByte() bool

func (MemTypeMock) IsKiloByte

func (m MemTypeMock) IsKiloByte() bool

func (MemTypeMock) IsMegaByte

func (m MemTypeMock) IsMegaByte() bool

type StringType

type StringType struct {
	Key   string
	Value string
}

StringType represents a pair of key values that the value is a string.

func (StringType) Bytes

func (s StringType) Bytes() []byte

Bytes returns the byte slice representation of the type.

func (StringType) Equal

func (s StringType) Equal(other DataType) bool

Equal compares both keys and values and returns true if they are equal.

Jump to

Keyboard shortcuts

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