misc

package
v0.0.0-...-d57715f Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TextBlack = iota + 30
	TextRed
	TextGreen
	TextYellow
	TextBlue
	TextMagenta
	TextCyan
	TextWhite
)
View Source
const (
	KB uint64 = 1 << (10 * iota)
	MB
	GB
)

Nolint: megacheck, deadcode, varcheck.

View Source
const FormatTime = "2006-01-02 15:04:05"

Variables

View Source
var UUID = &IDUtils{}

Functions

func BeginsWith

func BeginsWith(s, expr string) bool

BeginsWith returns true when a given expression is found at the start of the input string Unlike `strings.HasPrefix`, the expression can be a regular expression rather than a fixed string

func Bool

func Bool(v bool) *bool

Bool returns a pointer to v.

func ByteMap

func ByteMap(m *map[string][]byte)

ByteMap initializes m when it points to nil.

func ConvTimeInLocation

func ConvTimeInLocation(t time.Time, local string) (time.Time, error)

func Cyan

func Cyan(msg string) string

func EndsWith

func EndsWith(s, expr string) bool

EndsWith returns true when a given expression is found at the end of the input string Unlike `strings.HasSuffix`, the expression can be a regular expression rather than a fixed string

func ExitSignalHandler

func ExitSignalHandler(onExit func())

func FuncCaller

func FuncCaller() string

func GetIniValueByKey

func GetIniValueByKey(iniFile *ini.File, key string) (value string, err error)

func GetRegexNamedGroups

func GetRegexNamedGroups(text string, expression *regexp.Regexp) (map[string]string, error)

GetRegexNamedGroups returns the strings captured by a regular expression with named groups It returns an error when no named groups were in the regular expression It returns nil when the expression did not match

func GetRegexPositionalGroups

func GetRegexPositionalGroups(text string, expression *regexp.Regexp) ([]string, error)

GetRegexPositionalGroups returns the strings captured by a regular expression with positional groups It returns an error when named groups were in the regular expression It returns nil when the expression did not match

func Green

func Green(msg string) string

func IPAddress

func IPAddress() (ipAddr string, err error)

func InStringSlice

func InStringSlice(slice []string, value string) bool

func Int32

func Int32(v int32) *int32

Int32 returns a pointer to v.

func Int64

func Int64(v int64) *int64

Int64 returns a pointer to v.

func InterfaceMapHash32

func InterfaceMapHash32(msg map[string]interface{}) (string, error)

func IsRetryFailure

func IsRetryFailure(err error) bool

func IsStringSliceEqual

func IsStringSliceEqual(slice1, slice2 []string) bool

func IsSubnet

func IsSubnet(dstNetStr string, existNetStr string) (bool, error)

func LOC

func LOC() *time.Location

func LOCWithName

func LOCWithName(name string) *time.Location

func LoadIni

func LoadIni(source interface{}) (iniFile *ini.File, err error)

LoadIni load ini data sources. source arguments can be mixed of file name with string type, or raw data in []byte.

func MD5Hash

func MD5Hash(input string) string

func Matches

func Matches(s string, expr string) bool

Matches returns true when a given expression matches the input string

func Max

func Max(a, b uint64) uint64

Max returns the largest int64 that was passed in the arguments.

func Min

func Min(a, b uint64) uint64

Min returns the smallest int64 that was passed in the arguments.

func ParseKVs

func ParseKVs(text string) (res map[string]string)

func PrintFatalError

func PrintFatalError(err error)

func PrintMsg

func PrintMsg(msg string, strs ...string)

func Red

func Red(msg string) string

func Retry

func Retry(interval time.Duration, maxRetries int, f ConditionFunc) error

Retry retries f every interval until after maxRetries. The interval won't be affected by how long f takes. For example, if interval is 3s, f takes 1s, another f will be called 2s later. However, if f takes longer than interval, it will be delayed.

func SetColor

func SetColor(msg string, conf, bg, text int) string

func SizeToBytes

func SizeToBytes(s string) (uint64, error)

SizeToBytes parses a string formatted by ByteSize as bytes. K = 1024 M = 1024 * K G = 1024 * M

func String

func String(v string) *string

String returns a pointer to v.

func StringMap

func StringMap(m *map[string]string)

StringMap initializes m when it points to nil.

func TimeParseInLocal

func TimeParseInLocal(timeStr string) (*time.Time, error)

func TimeParseInLocation

func TimeParseInLocation(timeStr string, local string) (*time.Time, error)

func ToUpperStringSlice

func ToUpperStringSlice(slice []string) []string

func UnsafeMergeMap

func UnsafeMergeMap(tgt map[string]interface{}, src map[string]interface{}) map[string]interface{}

func UnsafeMergeStringMap

func UnsafeMergeStringMap(tgt map[string]string, src map[string]string) map[string]string

func ValidateCIDR

func ValidateCIDR(cidr string) bool

func White

func White(msg string) string

func YamlToJSON

func YamlToJSON(y string) (j string, err error)

YamlToJSON converts yaml to json string

func Yellow

func Yellow(msg string) string

Types

type ConditionFunc

type ConditionFunc func() (bool, error)

type IDUtils

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

func (*IDUtils) GetId

func (u *IDUtils) GetId(domain string) (id string, err error)

type RetryError

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

func (*RetryError) Error

func (e *RetryError) Error() string

Jump to

Keyboard shortcuts

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