misc

package module
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 24 Imported by: 37

README

Package misc implements a differents trivial functions

Documentation

Overview

Package misc implements a differents trivial functions

Package misc implements a differents trivial functions

Index

Constants

View Source
const (
	// ExPanic --
	ExPanic = 70
	// ExStopped --
	ExStopped = 1
	// ExVersion --
	ExVersion = 64
	// ExMissingConfigFile --
	ExMissingConfigFile = 66
	// ExIncorrectConfigFile --
	ExIncorrectConfigFile = 78
	// ExConfigIncorrect --
	ExConfigIncorrect = 78
	// ExConfigErrors --
	ExConfigErrors = 78
	// ExCreateListenerError --
	ExCreateListenerError = 71
	// ExStartListenerError --
	ExStartListenerError = 71
	// ExServiceInitializationError --
	ExServiceInitializationError = 71
	// ExServiceError --
	ExServiceError = 71
	// ExAccessDenied --
	ExAccessDenied = 77
	// ExProgrammerError --
	ExProgrammerError = 70
)

Appliction exit codes

View Source
const DateFormat string = "02-01-2006"

DateFormat -- standard format of the date

View Source
const DateFormatRev string = "2006-01-02"

DateFormatRev -- reversed format of the date

View Source
const DateTimeFormat string = DateFormat + " " + TimeFormat

DateTimeFormat -- format of the date and time

View Source
const DateTimeFormatJSON string = DateTimeFormatJSONWithoutZ + "Z"
View Source
const DateTimeFormatJSONTZ string = DateFormatRev + "T" + TimeFormatWithMS + DateTimeFormatTZ

DateTimeFormatJSONTZ -- JSON format with TZ

View Source
const DateTimeFormatJSONWithoutZ string = DateFormatRev + "T" + TimeFormatWithMS

DateTimeFormatJSON -- JSON format

View Source
const DateTimeFormatRev string = DateFormatRev + " " + TimeFormat

DateTimeFormatRev -- standard format of the date and time with reversed date

View Source
const DateTimeFormatRevWithMS string = DateFormatRev + " " + TimeFormatWithMS

DateTimeFormatRevWithMS -- standard format of the date and time with reversed date and milliseconds

View Source
const DateTimeFormatShortJSON string = DateFormatRev + "T" + TimeFormat

DateTimeFormatShortJSON -- Short JSON format

View Source
const DateTimeFormatShortJSONTZ string = DateFormatRev + "T" + TimeFormat + DateTimeFormatTZ

DateTimeFormatShortJSONTZ -- Short JSON format with TZ

View Source
const DateTimeFormatTZ = "Z07:00"

DateTimeFormatTZ --

View Source
const DateTimeFormatWithMS string = DateFormat + " " + TimeFormatWithMS

DateTimeFormatWithMS -- standard format of the date and time with milliseconds

View Source
const (
	DefaultEnvFile = ".env"
)
View Source
const EOS string = "\n"

EOS -- EndOfString

View Source
const TimeFormat string = "15:04:05"

TimeFormat -- format of the time

View Source
const TimeFormatWithMS string = "15:04:05.000"

TimeFormatWithMS -- format of the time with milliseconds

Variables

View Source
var (

	// Logger --
	Logger loggerFunc
)
View Source
var (
	// TEST -- test mode
	TEST = false
)

Functions

func AbsPath

func AbsPath(name string) (string, error)

AbsPath --

func AbsPathEx added in v0.1.4

func AbsPathEx(name string, base string) (string, error)

AbsPathEx --

func AddExitFunc

func AddExitFunc(name string, f ExitFunc, param any)

AddExitFunc --

func AppExecName

func AppExecName() string

AppExecName -- name of the application executable file

func AppExecPath

func AppExecPath() string

AppExecPath -- full path of the application executable file

func AppFullName

func AppFullName() string

AppFullName -- application name with full path

func AppName

func AppName() string

AppName -- name of the application executable file without last extension

func AppStartTime

func AppStartTime() time.Time

AppStartTime -- time of the apptication start

func AppStarted

func AppStarted() bool

AppStarted -- is application started?

func AppTags added in v0.1.14

func AppTags() string

AppTags -- application tags

func AppVersion

func AppVersion() string

AppVersion -- application version

func AppWorkDir

func AppWorkDir() string

AppWorkDir -- directory where application started from

func BaseType added in v1.1.5

func BaseType(srcT reflect.Type) (t reflect.Type)

func BuildTime

func BuildTime() string

BuildTime --

func BuildTimeTS

func BuildTimeTS() time.Time

BuildTimeTS --

func CheckTimePrecision added in v0.1.38

func CheckTimePrecision(precision string, upToSecond bool) bool

CheckTimePrecision --

func Copyright() string

Copyright --

func DelExitFunc

func DelExitFunc(name string)

DelExitFunc --

func Duration2Interval added in v1.1.4

func Duration2Interval(d time.Duration) string

func Exit

func Exit()

Exit -- exit application

func ExitCode

func ExitCode() int

ExitCode -- get current exit code

func GetFuncName

func GetFuncName(shift int, shortName bool) string

GetFuncName -- name of the function from call stack

func GetMyIPs

func GetMyIPs() (map[string]bool, error)

GetMyIPs --

func GzipPack added in v0.1.18

func GzipPack(data io.Reader) (b *bytes.Buffer, err error)

GzipPack -- data will be truncated by ReadFrom!

func GzipRepack added in v0.1.18

func GzipRepack(data io.Reader) (b *bytes.Buffer, err error)

GzipRepack -- data will be truncated by ReadFrom!

func GzipUnpack added in v0.1.18

func GzipUnpack(data io.Reader) (b *bytes.Buffer, err error)

GzipUnpack -- data will be truncated by ReadFrom!

func Iface2Bool added in v0.1.33

func Iface2Bool(x any) (v bool, err error)

Iface2Bool --

func Iface2Float

func Iface2Float(x any) (v float64, err error)

Iface2Float --

func Iface2IfacePtr added in v0.1.51

func Iface2IfacePtr(src any, dstPtr any) (err error)

func Iface2Int

func Iface2Int(x any) (v int64, err error)

Iface2Int --

func Iface2String

func Iface2String(x any) (v string, err error)

Iface2String --

func Iface2Time added in v0.1.56

func Iface2Time(x any) (v time.Time, err error)

Iface2Time --

func Iface2Uint

func Iface2Uint(x any) (v uint64, err error)

Iface2Uint --

func Int2Interval added in v1.1.4

func Int2Interval(d int64) string

func Interval2Duration added in v0.1.38

func Interval2Duration(interval string) (time.Duration, error)

Interval2Duration --

func Interval2Int64 added in v0.1.38

func Interval2Int64(interval string) (int64, error)

Interval2Int64 --

func IsDebug

func IsDebug() bool

IsDebug --

func IsMyIP

func IsMyIP(ip string) (bool, error)

IsMyIP --

func IsNil added in v1.1.12

func IsNil(obj any) bool

func JoinByteSlices added in v0.1.45

func JoinByteSlices(prefix []byte, suffix []byte, sep []byte, in [][]byte) (out []byte)

func JoinStrings added in v0.1.45

func JoinStrings(prefix string, suffix string, sep string, in []string) (out string)

func LoadEnv added in v0.1.24

func LoadEnv(fileName string) (e error)

LoadEnv --

func LogProcessingTime

func LogProcessingTime(facility string, level string, id uint64, module string, message string, t0 int64) int64

LogProcessingTime --

func MarshalBin

func MarshalBin(src any) (buf *bytes.Buffer, err error)

MarshalBin --

func NormalizeSlashes

func NormalizeSlashes(u string) string

NormalizeSlashes --

func NowUTC

func NowUTC() time.Time

NowUTC --

func NowUnix added in v0.1.23

func NowUnix() int64

NowUnix --

func NowUnixNano added in v0.1.23

func NowUnixNano() int64

NowUnixNano --

func ParseJSONtime added in v0.1.25

func ParseJSONtime(s string) (t time.Time, err error)

ParseJSONtime --

func SetExitTimeouts added in v0.1.50

func SetExitTimeouts(newTerminationTimeout time.Duration, newKillingTimeout time.Duration) (prevTerminationTimeout time.Duration, prevKillingTimeout time.Duration)

func Sha512Hash added in v0.1.34

func Sha512Hash(p []byte) []byte

Sha512Hash --

func Sleep

func Sleep(duration time.Duration) bool

Sleep --

func SplitAndTrim added in v1.1.9

func SplitAndTrim(src string, delimiter string) (dst []string)

func StopApp

func StopApp(code int)

StopApp -- set exit code and raise application stop

func StructTagName added in v1.1.7

func StructTagName(f *reflect.StructField, tag string) (name string)

func StructTags added in v1.1.7

func StructTags(s any, fields []string, tag string) (names []string, err error)

func Time2JSON added in v0.1.27

func Time2JSON(t time.Time) string

Time2JSON --

func Time2JSONtz added in v0.1.35

func Time2JSONtz(t time.Time) string

Time2JSONtz --

func Time2JSONutc added in v0.1.35

func Time2JSONutc(t time.Time) string

Time2JSONutc --

func TimePrecisionDivider added in v0.1.38

func TimePrecisionDivider(precision string, upToSecond bool) (int64, error)

TimePrecisionDivider --

func TrimStringAsFloat

func TrimStringAsFloat(s string) string

TrimStringAsFloat --

func UnixNano2JSON added in v0.1.27

func UnixNano2JSON(ts int64) string

UnixNano2JSON --

func UnixNano2UTC added in v0.1.26

func UnixNano2UTC(ts int64) time.Time

UnixNano2UTC --

func UnmarshalBin

func UnmarshalBin(buf *bytes.Buffer, dst any) (err error)

UnmarshalBin --

func UnsafeByteSlice2String added in v0.1.42

func UnsafeByteSlice2String(b []byte) (s string)

UnsafeByteSlice2String -- fast convert []byte to string without memory allocs Don't forget to use runtime.KeepAlive(b) in the caller if necessary!

func UnsafeString2ByteSlice added in v0.1.42

func UnsafeString2ByteSlice(s string) (b []byte)

UnsafeString2ByteSlice -- fast convert string to []byte without memory allocs Don't forget to use runtime.KeepAlive(s) in the caller if necessary! Don't try to change result without thinking hard before that!

func WaitingForStop

func WaitingForStop()

WaitingForStop --

func WaitingForStopChan added in v0.1.55

func WaitingForStopChan() <-chan time.Time

WaitingForStopChan --

Types

type BoolMap added in v0.1.9

type BoolMap map[string]bool

BoolMap --

type ByteSliceMap added in v0.1.11

type ByteSliceMap map[string][]byte

ByteSliceMap --

type CallStackFrame

type CallStackFrame struct {
	FuncName string
	FileName string
	Line     int
}

CallStackFrame -- call stack element

func GetCallStack

func GetCallStack(shift int) []CallStackFrame

GetCallStack -- get call stack

type CtxInt64 added in v0.1.5

type CtxInt64 int64

CtxInt64 --

type CtxKey added in v0.1.54

type CtxKey string

type CtxString added in v0.1.5

type CtxString string

CtxString --

type CtxUint64 added in v0.1.5

type CtxUint64 uint64

CtxUint64 --

type Error

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

Error --

func MakeError

func MakeError(code int, format string, options ...any) *Error

MakeError --

func (*Error) Code

func (me *Error) Code() int

Code --

func (*Error) Error

func (me *Error) Error() string

Error --

func (*Error) SetCode

func (me *Error) SetCode(code int)

SetCode --

func (*Error) SetMessage

func (me *Error) SetMessage(format string, options ...any)

SetMessage --

type ExitFunc

type ExitFunc func(code int, param any)

ExitFunc --

type Float64Map added in v0.1.9

type Float64Map map[string]float64

Float64Map --

type Int64Map added in v0.1.9

type Int64Map map[string]int64

Int64Map --

type IntMap added in v0.1.9

type IntMap map[string]int

IntMap --

type InterfaceMap

type InterfaceMap map[string]any

InterfaceMap --

func (InterfaceMap) GetBool added in v0.1.33

func (m InterfaceMap) GetBool(name string) (v bool, err error)

GetBool --

func (InterfaceMap) GetFloat

func (m InterfaceMap) GetFloat(name string) (v float64, err error)

GetFloat --

func (InterfaceMap) GetInt

func (m InterfaceMap) GetInt(name string) (v int64, err error)

GetInt --

func (InterfaceMap) GetString

func (m InterfaceMap) GetString(name string) (v string, err error)

GetString --

func (InterfaceMap) GetTime added in v0.1.56

func (m InterfaceMap) GetTime(name string) (v time.Time, err error)

GetTime --

func (InterfaceMap) GetUint

func (m InterfaceMap) GetUint(name string) (v uint64, err error)

GetUint --

type Messages added in v0.1.21

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

Messages --

func NewMessages added in v0.1.32

func NewMessages() *Messages

NewMessages --

func (*Messages) Add added in v0.1.21

func (m *Messages) Add(msg string, params ...any)

Add --

func (*Messages) AddError added in v0.1.21

func (m *Messages) AddError(err error)

AddError --

func (*Messages) Content added in v1.1.11

func (m *Messages) Content() []string

func (*Messages) Error added in v0.1.21

func (m *Messages) Error(separators ...string) error

Error --

func (*Messages) Len added in v0.1.30

func (m *Messages) Len() int

Len --

func (*Messages) String added in v0.1.21

func (m *Messages) String(separators ...string) string

String --

type Replace added in v0.1.8

type Replace []replaceDef

Replace --

func NewReplace added in v0.1.8

func NewReplace() *Replace

NewReplace --

func (*Replace) Add added in v0.1.8

func (r *Replace) Add(re string, replaceTo string) error

Add --

func (*Replace) AddMulti added in v0.1.8

func (r *Replace) AddMulti(list map[string]string) error

AddMulti --

func (*Replace) Concat added in v0.1.37

func (r *Replace) Concat(r2 Replace) error

Concat --

func (*Replace) Do added in v0.1.8

func (r *Replace) Do(s string) string

Do --

type StringMap

type StringMap map[string]string

StringMap --

func StructTagOpts added in v1.1.7

func StructTagOpts(f *reflect.StructField, tag string) (opts StringMap)

type Uint64Map added in v0.1.9

type Uint64Map map[string]uint64

Uint64Map --

type UintMap added in v0.1.9

type UintMap map[string]uint

UintMap --

Jump to

Keyboard shortcuts

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