helpers

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 27, 2017 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package helpers contains helpers functions.

Index

Constants

View Source
const LAST_SUNDAY = -1

LAST_SUNDAY represents last sunday in month.

Variables

This section is empty.

Functions

func CeilDateSeconds

func CeilDateSeconds(step float64) float64

CeilDateSeconds rounds up seconds to whole seconds, minutes, hours, days.

func CeilIn24System

func CeilIn24System(input float64) float64

CeilIn24System - 1, 2, 3, 6, 12, 24

func CeilIn60System

func CeilIn60System(input float64) float64

CeilIn60System - 1, 2, 5, 10, 15, 30

func CeilWithStep

func CeilWithStep(input float64, step float64) float64

CeilWithStep - ceil value with given step.

func CmpDecimal

func CmpDecimal(a bson.Decimal128, b bson.Decimal128) int

CmpDecimal compares Decimal.

func CmpDecimalProxy

func CmpDecimalProxy(a DecimalProxy, b DecimalProxy) int

CmpDecimalProxy compares DecimalProxy.

func DataToString

func DataToString(data interface{}) string

DataToString formats structured data to string.

func DecimalToDouble

func DecimalToDouble(input bson.Decimal128) float64

DecimalToDouble or panic.

func DoubleToDecimal

func DoubleToDecimal(input float64) bson.Decimal128

DoubleToDecimal or panic.

func FloorWithStep

func FloorWithStep(input float64, step float64) float64

FloorWithStep - floor value with given step.

func FromDoubleTo

func FromDoubleTo(t string, v float64, location *time.Location) interface{}

FromDoubleTo converts float64 to some selected types or panic.

func GetBSONFieldName

func GetBSONFieldName(t interface{}, name string) string

GetBSONFieldName gets bson tag name from struct field.

func GetJSONFieldName

func GetJSONFieldName(t interface{}, name string) string

GetJSONFieldName gets json tag name from struct field.

func GetYAMLFieldName

func GetYAMLFieldName(t interface{}, name string) string

GetYAMLFieldName gets yaml tag name from struct field.

func HashData

func HashData(input interface{}) uint32

HashData hash structured data regardless of the order

func InStringSlice

func InStringSlice(v string, s []string) bool

InStringSlice return true if value is in slice.

func MarshalToJSON

func MarshalToJSON(data interface{}) string

MarshalToJSON or panic.

func MarshalToYAML

func MarshalToYAML(data interface{}) string

MarshalToYAML or panic.

func MaxBool

func MaxBool(a, b bool) bool

MaxBool gets maximum of two bool values.

func MaxDate

func MaxDate(a, b time.Time) time.Time

MaxDate gets maximum of time.Time values.

func MaxDecimal

func MaxDecimal(a, b bson.Decimal128) bson.Decimal128

MaxDecimal gets maximum of two bson.Decimal128 values.

func MaxDouble

func MaxDouble(a, b float64) float64

MaxDouble gets maximum of two double values.

func MaxInt

func MaxInt(a, b int) int

MaxInt gets maximum of two int values.

func MaxInt32

func MaxInt32(a, b int32) int32

MaxInt32 gets minimum of two int32 values.

func MaxLong

func MaxLong(a, b int64) int64

MaxLong gets maximum of two int64 values.

func MaxObjectId

func MaxObjectId(a, b bson.ObjectId) bson.ObjectId

MaxObjectId gets maximum of two ObjectId values.

func MaxString

func MaxString(a, b string) string

MaxString gets maximum of two string values.

func MaxT

func MaxT(t string, a interface{}, b interface{}) interface{}

MaxT gets maximum of two values.

func MaxTimestamp

func MaxTimestamp(a, b bson.MongoTimestamp) bson.MongoTimestamp

MaxTimestamp gets maximum of two bson.MongoTimestamp values.

func MaxUInt

func MaxUInt(a, b uint) uint

MaxUInt gets maximum of two uint values.

func MinBool

func MinBool(a, b bool) bool

MinBool gets maximum of two bool values.

func MinDate

func MinDate(a, b time.Time) time.Time

MinDate gets minimum of two time.Time values.

func MinDecimal

func MinDecimal(a, b bson.Decimal128) bson.Decimal128

MinDecimal gets minimum of two bson.Decimal128 values.

func MinDouble

func MinDouble(a, b float64) float64

MinDouble gets minimum of two double values.

func MinInt

func MinInt(a, b int) int

MinInt gets minimum of two int values.

func MinInt32

func MinInt32(a, b int32) int32

MinInt32 gets minimum of two int32 values.

func MinLong

func MinLong(a, b int64) int64

MinLong gets minimum of two int64 values.

func MinObjectId

func MinObjectId(a, b bson.ObjectId) bson.ObjectId

MinObjectId gets minimum of two ObjectId values.

func MinString

func MinString(a, b string) string

MinString gets minimum of two string values.

func MinT

func MinT(t string, a interface{}, b interface{}) interface{}

MinT gets minimum of two values.

func MinTimestamp

func MinTimestamp(a, b bson.MongoTimestamp) bson.MongoTimestamp

MinTimestamp gets minimum of two bson.MongoTimestamp values.

func MinUInt

func MinUInt(a, b uint) uint

MinUInt gets minimum of two uint values.

func ParseDate

func ParseDate(input string) time.Time

ParseDate or panic.

func ParseDecimal

func ParseDecimal(input string) bson.Decimal128

ParseDecimal or panic.

func PrintData

func PrintData(data interface{})

PrintData prints structured data

func ReadChannelToNull

func ReadChannelToNull(ch interface{}) int

ReadChannelToNull reads values from channel to null. Useful for testing.

func SafeToBool

func SafeToBool(value interface{}) bool

SafeToBool converts interface to bool or fail.

func SafeToDate

func SafeToDate(value interface{}) time.Time

SafeToDate converts interface to time.Time or fail.

func SafeToDecimal

func SafeToDecimal(value interface{}) bson.Decimal128

SafeToDecimal converts interface to decimal or fail.

func SafeToDouble

func SafeToDouble(value interface{}) float64

SafeToDouble converts interface to float64 or fail.

func SafeToInt

func SafeToInt(value interface{}) int

SafeToInt converts interface to int or fail.

func SafeToInt32

func SafeToInt32(value interface{}) int32

SafeToInt32 converts interface to int32 or fail.

func SafeToLong

func SafeToLong(value interface{}) int64

SafeToLong converts interface to long or fail.

func SafeToObjectId

func SafeToObjectId(value interface{}) bson.ObjectId

SafeToObjectId converts interface to ObjectId or fail.

func SafeToString

func SafeToString(value interface{}) string

SafeToString converts interface to string or fail.

func SafeToTimestamp

func SafeToTimestamp(value interface{}) bson.MongoTimestamp

SafeToTimestamp converts interface to bson.MongoTimestamp or fail.

func ToDouble

func ToDouble(input interface{}) float64

ToDouble converts some selected types to float64 or panic.

func ToUInt

func ToUInt(input interface{}) uint

ToUInt converts some selected types to uint or panic.

func VersionToString

func VersionToString(version ...int) string

VersionToString converts MongoDB version to string

Types

type DecimalProxy

type DecimalProxy struct {
	H, L uint64
}

DecimalProxy serves to circumvent non-exported attributes of bson.Decimal type.

func ToDecimalProxy

func ToDecimalProxy(value bson.Decimal128) DecimalProxy

ToDecimalProxy converts bson.Decimal128 to DecimalProxy.

func (*DecimalProxy) Exponent

func (d *DecimalProxy) Exponent() int

Exponent gets number exponent.

func (*DecimalProxy) Parts

func (d *DecimalProxy) Parts() (uint64, uint64)

Parts gets number parts.

func (*DecimalProxy) Positive

func (d *DecimalProxy) Positive() int

Positive gets number sign.

type Timezone

type Timezone struct {
	TimeZoneChanging         bool
	WinterTimeOffset         int
	WinterTimeStartDate      time.Time
	WinterTimeStartMonth     int
	WinterTimeStartMonthDays int
	WinterTimeStartSunday    int // -1 means last sunday of month
	SummerTimeOffset         int
	SummerTimeStartDate      time.Time
	SummerTimeStartMonth     int
	SummerTimeStartMonthDays int
	SummerTimeStartSunday    int // -1 means last sunday of month
}

Timezone struct represents information about timezone.

func GetTimezone

func GetTimezone(location *time.Location) *Timezone

GetTimezone returns information about given timezone.

Jump to

Keyboard shortcuts

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