helper

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2020 License: LGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxUint = ^uint(0)
	MinUint = 0
	MaxInt  = int(MaxUint >> 1)
	MinInt  = -MaxInt - 1
)

Variables

This section is empty.

Functions

func CastInt64ToUint

func CastInt64ToUint(in *int64) (uint, error)

CastInt64ToUint safely casts the given int64 pointer value to uint value. If the input is nil then an error will be returned. If the input is < 0 then 0 is returned.

func CastToStringMapSlice

func CastToStringMapSlice(iface interface{}) []map[string]string

CastToStringMapSlice casts the given input to a slice of string:string map's

func CastToStringMapSliceE

func CastToStringMapSliceE(iface interface{}) ([]map[string]string, error)

CastToStringMapSliceE casts the given input to a slice of string:string map's

func Hash

func Hash(s string) uint32

Hash creates a 32-bit FNV-1a hash out of the given string.

func IncUint

func IncUint(value uint, by int) uint

IncUint increments the given value (unsigned) by the given amount (signed) and returns the result as unsigned int (safe from under-/overflow)

func Must

func Must(v interface{}, err error) interface{}

Must is a helper that checks if a error returned by a function is nil in this case Must will end the program with a fatal printing out the error. If the error is nil the result of the function will be returned.

func SubUint

func SubUint(a uint, by uint) int

SubUint substracts two uint's and returns the signed difference Avoids over-/underflow.

func SubUint2

func SubUint2(a uint, by uint) uint

SubUint2 substracts two uint's and returns the unsigned difference Avoids over-/underflow.

Types

type LatestGradient

type LatestGradient struct {
	Value     float32
	Timestamp time.Time
	// contains filtered or unexported fields
}

LatestGradient is a structure that can be used to calculate the gradient of the two latest values of a field.

func (*LatestGradient) Get

func (lg *LatestGradient) Get(value float32, timestamp time.Time) float32

Get returns the gradient.

func (*LatestGradient) Update

func (lg *LatestGradient) Update(value float32, timestamp time.Time)

Update sets new values for the gradient.

func (*LatestGradient) UpdateAndGet

func (lg *LatestGradient) UpdateAndGet(value float32, timestamp time.Time) float32

UpdateAndGet is a thread safe method to calculate the gradient between the latest value and the current value. With each call to UpdateAndGet the given value and timestamp are stored internally. Furthermore the gradient is calculated by (currentValue-lastValue)/(currentTimeStamp-lastTimestamp).

type SimpleTime added in v0.0.12

type SimpleTime struct {
	Hour   uint `json:"hour,omitempty"`
	Minute uint `json:"minute,omitempty"`
}

SimpleTime just to express hours and minutes

func NewTime added in v0.0.12

func NewTime(hour, minute uint) (SimpleTime, error)

NewTime creates a new SimpleTime instance based on the given parameters

func NewTimeFromMinute added in v0.0.12

func NewTimeFromMinute(minutes uint) (SimpleTime, error)

NewTimeFromMinute creates a new SimpleTime instance based on the given parameters

func (SimpleTime) Minutes added in v0.0.12

func (s SimpleTime) Minutes() uint

Minutes returns the time in minutes

func (SimpleTime) String added in v0.0.12

func (s SimpleTime) String() string

Jump to

Keyboard shortcuts

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