utils

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Unknown is unresolved OS type
	UnknownFileType = iota
	// Win is Windows type
	WinFileType
	// Unix is *nix OS types
	UnixFileType
)

Used by IsFilePath func

View Source
const (
	// StdLen is the minimum string length required to achieve ~95 bits of entropy.
	StdLen = 16
	// MaxLen is the maximum length possible for generated strings
	MaxLen = 1048576
)

Variables

View Source
var StdChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")

StdChars is a set of standard characters allowed in Base64 string.

Functions

func AsBool

func AsBool(value interface{}) (bool, error)

func AsFloat

func AsFloat(value interface{}) (float64, error)

func AsInt

func AsInt(value interface{}) (int, error)

func AsString

func AsString(value interface{}) (string, error)

func AsTime

func AsTime(value interface{}) (time.Time, error)

func FirstDayOfISOWeek

func FirstDayOfISOWeek(year int, week int, timezone *time.Location) time.Time

FirstDayOfISOWeek returns the date of the Monday in the given week/year

func GetUID

func GetUID(name string) (string, error)

func IsBitstring

func IsBitstring(str string) bool

IsBitstring check if the string is a bit string.

func IsDNSName

func IsDNSName(str string) bool

IsDNSName will validate the given string as a DNS name

func IsDialString

func IsDialString(str string) bool

IsDialString validates the given string for usage with the various Dial() functions

func IsEmailFormat

func IsEmailFormat(str string) bool

IsEmailFormat checks if the string is a valid email address format

func IsFilePath

func IsFilePath(str string) (bool, int)

IsFilePath check is a string is Win or Unix file path and returns it's type.

func IsFloat

func IsFloat(str string) bool

IsFloat check if the string is a float.

func IsHexadecimal

func IsHexadecimal(str string) bool

IsHexadecimal check if the string is a hexadecimal number.

func IsIP

func IsIP(str string) bool

IsIP checks if a string is either IP version 4 or 6 using the net package parser

func IsIPInRange

func IsIPInRange(rangeIPs []string, checkIP string) bool

IsIPInRange returns true if checkIP is in any of the specified ips or cidr ranges from rangeIPs

func IsInt

func IsInt(str string) bool

IsInt check if the string is an integer.

func IsNull

func IsNull(str string) bool

IsNull check if the string is null.

func IsPhoneNumberFormat

func IsPhoneNumberFormat(str string) bool

IsPhoneNumberFormat checks if the string is a valid phone number format

func IsPointer

func IsPointer(obj interface{}) bool

IsPointer checks if given interface is a pointer

func IsPort

func IsPort(str string) bool

IsPort checks if a string represents a valid port

func IsSimpleType

func IsSimpleType(kind reflect.Kind) bool

IsSimpleType checks if given t ype is a simple Go type

func IsTruthy

func IsTruthy(input string) bool

IsTruthy checks if the given input is a value that can mean true or false

func IsUIDHex

func IsUIDHex(s string) bool

func IsValidEmailHost

func IsValidEmailHost(email string) bool

IsValidEmailHost tries to do a SMTP connection on the email host to validate if it's a valid email address or not

func IsValidIP

func IsValidIP(ip string) bool

func Matches

func Matches(str, pattern string) bool

Matches check if string matches the pattern (pattern is regular expression) In case of error return false

func RandomString

func RandomString() string

RandomString returns a new random string of the standard length, consisting of standard characters.

func RandomStringLen

func RandomStringLen(length int) string

RandomStringLen returns a new random string of the provided length (0 < len < MaxLen), consisting of standard characters.

func SplitEmailToAccountAndDomain

func SplitEmailToAccountAndDomain(email string) (account, host string)

SplitEmailToAccountAndDomain splits an email address into account name and hostname

func TimeAgo

func TimeAgo(datetime time.Time) string

TimeAgo takes a time input and returns a string representation of how much time elapsed since the given time

func ToStringSlice

func ToStringSlice(list []int) []string

ToStringSlice converts the int slice to a string slice

func TrimAndLower

func TrimAndLower(str string) string

TrimAndLower returns a lowercase representation of the input

func Truthy

func Truthy(input string) bool

Truthy converts string values to their boolean representations. If input string is not found in the list of defined truthy values, false is returned.

FALSE values: NaN, undefined, null, "" (empty string), false, no, off, 0, untoggled, inactive TRUE values: true, yes, on, 1, toggled, active

func ValidUID

func ValidUID(uid string) bool

func WaitTermSignal

func WaitTermSignal() chan os.Signal

func WorkingDays

func WorkingDays(startDate time.Time, endDate time.Time) int

WorkingDays returns the number of working days between the two dates. It only calculates 5 working days a week and takes nothing else into consideration

Types

type ISO3166Entry

type ISO3166Entry struct {
	EnglishShortName string
	FrenchShortName  string
	Alpha2Code       string
	Alpha3Code       string
	Numeric          string
}

ISO3166Entry stores country codes

type UID

type UID string

func NewUID

func NewUID() UID

func UIDHex

func UIDHex(s string) UID

func (*UID) DecodeText

func (id *UID) DecodeText(ci *pgtype.ConnInfo, src []byte) error

func (UID) EncodeText

func (id UID) EncodeText(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)

func (UID) Equals

func (id UID) Equals(u UID) bool

func (UID) Hex

func (id UID) Hex() string

func (UID) MarshalJSON

func (id UID) MarshalJSON() ([]byte, error)

func (UID) MarshalText

func (id UID) MarshalText() ([]byte, error)

func (UID) String

func (id UID) String() string

func (UID) UUID

func (id UID) UUID() uuid.UUID

func (*UID) UnmarshalJSON

func (id *UID) UnmarshalJSON(data []byte) error

func (*UID) UnmarshalText

func (id *UID) UnmarshalText(data []byte) error

UnmarshalText turns *bson.ObjectId into an encoding.TextUnmarshaler.

func (UID) Valid

func (id UID) Valid() bool

type UIDsList

type UIDsList []UID

func (UIDsList) EncodeText

func (a UIDsList) EncodeText(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)

func (UIDsList) Has

func (a UIDsList) Has(id UID) bool

Directories

Path Synopsis
Package structs contains various utilities functions to work with structs.
Package structs contains various utilities functions to work with structs.
Package uuid provides RFC4122 UUIDs.
Package uuid provides RFC4122 UUIDs.
Package version implements semantic version according to semver.org 2.0.0 specs.
Package version implements semantic version according to semver.org 2.0.0 specs.

Jump to

Keyboard shortcuts

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