utils

package
v0.0.0-...-8122643 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DateNil = Date(0)
View Source
var TimeNil = time.Time{}

Functions

func AllMapKeys

func AllMapKeys[T1 comparable, T2 any](m map[T1]T2) []T1

func AllMapValues

func AllMapValues[T1 comparable, T2 any](m map[T1]T2) []T2

func AppendMap

func AppendMap[T any](m1 map[string]T, m2 map[string]T)

func AppendMapNew

func AppendMapNew(m1 map[string]interface{}, m2 map[string]interface{}) map[string]interface{}

func Base64Decode

func Base64Decode(data string) ([]byte, error)

func Base64Encode

func Base64Encode(data []byte) string

func BeginningOfDay

func BeginningOfDay(t time.Time) time.Time

func BoolToStr

func BoolToStr(val bool) string

func BuildString

func BuildString(sb *strings.Builder, parts ...string)

func ConcatSlices

func ConcatSlices[T any](start []T, slices ...[]T) []T

func ConcatStrings

func ConcatStrings(parts ...string) string

func CopyMap

func CopyMap(m map[string]interface{}) map[string]interface{}

func CopyMapOneLevel

func CopyMapOneLevel[T1 comparable, T2 any](m map[T1]T2) map[T1]T2

func DateConverter

func DateConverter(str string) reflect.Value

func DateReflectStr

func DateReflectStr(val reflect.Value) string

func DumpJson

func DumpJson(obj interface{}) string

func DumpPrettyJson

func DumpPrettyJson(obj interface{}) string

func EachStructTag

func EachStructTag(handler StructTagHandler, tag string, obj interface{}) error

func EndOfDay

func EndOfDay(t time.Time) time.Time

func FileExists

func FileExists(path string) bool

func FloatAlmostEqual

func FloatAlmostEqual[T Float](a, b T) bool

func FloatToDecimalStr

func FloatToDecimalStr(f float64, comma ...bool) string

func FloatToStr

func FloatToStr[T Float](val T) string

func FloatToStr2

func FloatToStr2[T Float](val T) string

func FloatToStr2Comma

func FloatToStr2Comma[T Float](val T) string

func FloatToStr2Hyphen

func FloatToStr2Hyphen[T Float](val T) string

func FloatToStr2Variant

func FloatToStr2Variant[T Float](val T, comma ...bool) string

func FloatToStr4

func FloatToStr4[T Float](val T) string

func FloatToStr4Comma

func FloatToStr4Comma[T Float](val T) string

func FloatToStr4Hyphen

func FloatToStr4Hyphen[T Float](val T) string

func FloatToStr4Variant

func FloatToStr4Variant[T Float](val T, comma ...bool) string

func FloatToStrComma

func FloatToStrComma[T Float](val T) string

func FormatCard

func FormatCard(pan string) string

func GenerateID

func GenerateID() string

func GenerateRand64

func GenerateRand64() string

func GenerateRandInt

func GenerateRandInt(length ...int) string

func IsDir

func IsDir(path string) bool

func IsFile

func IsFile(path string) bool

func IsNil

func IsNil[T interface{}](a T) bool

func IsTime

func IsTime(obj reflect.Value) bool

func List

func List(vals ...interface{}) []interface{}

func ListInterfaces

func ListInterfaces[T any](in ...T) []interface{}

func MakePath

func MakePath(filename string) error

func MapToStruct

func MapToStruct(in interface{}, out interface{}, tag ...string) error

func MaskCard

func MaskCard(pan string, maskPrefix ...bool) string

func MaskPhone

func MaskPhone(phone string) string

func Min

func Min(a, b int) int

func MoneyToDecimal

func MoneyToDecimal[T constraints.Integer](cents T) float64

func MoneyToDecimalStr

func MoneyToDecimalStr(cents int64, comma ...bool) string

func MoneyToInteger

func MoneyToInteger(dollars float64) int64

func MoneyToIntegerUp

func MoneyToIntegerUp(dollars float64) int64

func NumToStr

func NumToStr[T constraints.Integer](val T) string

func ObjectTypeName

func ObjectTypeName(obj interface{}) string

func OptionalArg

func OptionalArg[T any](defaultArg T, optional ...T) T

Select either default or optional value if the optional value is given in argumments.

func OptionalString

func OptionalString(defaultVal string, optional ...string) string

func ParseRuTime

func ParseRuTime(str string) (time.Time, error)

func ParseRuTimeShort

func ParseRuTimeShort(str string) (time.Time, error)

func ParseTime

func ParseTime(str string) (time.Time, error)

func ReadTemplate

func ReadTemplate(path string, name string, vals interface{}, language ...string) (string, error)

func ReadTemplateFile

func ReadTemplateFile(fileName string, vals interface{}) (string, error)

func RoundMoney

func RoundMoney(value float64) float64

func RoundMoneyDown

func RoundMoneyDown(value float64) float64

func RoundMoneyUp

func RoundMoneyUp(value float64) float64

func StrToBool

func StrToBool(s string) (bool, error)

func StrToFloat

func StrToFloat(s string) (float64, error)

func StrToInt

func StrToInt(s string) (int, error)

func StrToInt32

func StrToInt32(s string) (int32, error)

func StrToInt64

func StrToInt64(s string) (int64, error)

func StrToUint32

func StrToUint32(s string) (uint32, error)

func StrToUint64

func StrToUint64(s string) (uint64, error)

func Substr

func Substr(input string, start int, length int) string

func TimeConverter

func TimeConverter(str string) reflect.Value

func TimeRFC3339

func TimeRFC3339(t time.Time) string

func TimeReflectStr

func TimeReflectStr(val reflect.Value) string

func TimeToStr

func TimeToStr(t time.Time) string

func TimeToStrRu

func TimeToStrRu(t time.Time) string

func WalkDirExt

func WalkDirExt(handler WalkDirExtHandler, root string, ext string) error

Types

type Base64StringCoding

type Base64StringCoding struct {
}

func (*Base64StringCoding) Decode

func (b *Base64StringCoding) Decode(data string) ([]byte, error)

func (*Base64StringCoding) Encode

func (b *Base64StringCoding) Encode(data []byte) string

type Date

type Date int

func DateFromId

func DateFromId(id string) (Date, error)

func DateOfTime

func DateOfTime(t time.Time) Date

func StrToDate

func StrToDate(s string) (Date, error)

func Today

func Today() Date

func Yesterday

func Yesterday() Date

func (*Date) AsNumber

func (d *Date) AsNumber() string

func (*Date) Day

func (d *Date) Day() int

func (*Date) IsNil

func (d *Date) IsNil() bool

func (*Date) MMonth

func (d *Date) MMonth() Month

func (*Date) MarshalJSON

func (d *Date) MarshalJSON() ([]byte, error)

func (*Date) Month

func (d *Date) Month() int

func (*Date) Set

func (d *Date) Set(year int, month int, day int)

func (*Date) SetTime

func (d *Date) SetTime(t time.Time)

func (*Date) String

func (d *Date) String() string

func (*Date) StringRu

func (d *Date) StringRu() string

func (*Date) StringRuShort

func (d *Date) StringRuShort() string

func (*Date) Time

func (d *Date) Time() time.Time

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(b []byte) error

func (*Date) Year

func (d *Date) Year() int

type FileWriteReopen

type FileWriteReopen struct {
	Path string
	File *os.File
}

func (*FileWriteReopen) Write

func (f *FileWriteReopen) Write(p []byte) (n int, err error)

type Float

type Float interface {
	float32 | float64
}

type HexStringCoding

type HexStringCoding struct {
	UpperCase bool
}

func (*HexStringCoding) Decode

func (h *HexStringCoding) Decode(data string) ([]byte, error)

func (*HexStringCoding) Encode

func (h *HexStringCoding) Encode(data []byte) string

type Month

type Month int

func CurrentMonth

func CurrentMonth() Month

func MakeMonth

func MakeMonth() Month

func MonthFromDate

func MonthFromDate(d Date) Month

func MonthFromId

func MonthFromId(id string) (Month, error)

func MonthFromShortString

func MonthFromShortString(str string, reverse bool) (Month, error)

func MonthFromString

func MonthFromString(str string) (Month, error)

func MonthFromTime

func MonthFromTime(t time.Time) Month

func (*Month) AsNumber

func (m *Month) AsNumber() string

func (*Month) AsShortNumber

func (m *Month) AsShortNumber() string

func (*Month) AsShortNumberReverse

func (m *Month) AsShortNumberReverse() string

func (*Month) MarshalJSON

func (m *Month) MarshalJSON() ([]byte, error)

func (*Month) Month

func (m *Month) Month() int

func (*Month) Next

func (m *Month) Next() Month

func (*Month) Prev

func (m *Month) Prev() Month

func (*Month) Set

func (m *Month) Set(year int, month int)

func (*Month) SetTime

func (m *Month) SetTime(t time.Time)

func (*Month) String

func (m *Month) String() string

func (*Month) Time

func (m *Month) Time() time.Time

func (*Month) UnmarshalJSON

func (m *Month) UnmarshalJSON(b []byte) error

func (*Month) Year

func (m *Month) Year() int

type MonthData

type MonthData interface {
	GetMonth() Month
	SetMonth(m Month)
}

type MonthDataBase

type MonthDataBase struct {
	Month Month `gorm:"primary_key;index;index:,unique,composite:u_month" json:"month"`
}

func (*MonthDataBase) GetMonth

func (w *MonthDataBase) GetMonth() Month

func (*MonthDataBase) InitMonth

func (w *MonthDataBase) InitMonth()

func (*MonthDataBase) SetMonth

func (w *MonthDataBase) SetMonth(m Month)

type StringCoding

type StringCoding interface {
	Encode(data []byte) string
	Decode(data string) ([]byte, error)
}

type StructTagHandler

type StructTagHandler = func(tagValue string) error

type WalkDirExtHandler

type WalkDirExtHandler = func(filePath string) error

type WithStringCoder

type WithStringCoder interface {
	Coder() StringCoding
}

type WithStringCoderBase

type WithStringCoderBase struct {
	StringCoding StringCoding
}

func (*WithStringCoderBase) Coder

func (w *WithStringCoderBase) Coder() StringCoding

func (*WithStringCoderBase) Construct

func (w *WithStringCoderBase) Construct(encoder ...StringCoding)

Jump to

Keyboard shortcuts

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