handy: github.com/miguelpragier/handy Index | Files

package handy

import "github.com/miguelpragier/handy"

Package handy is a toolbelt with utilities and helpers like validators, sanitizers and string formatters. There are routines to filter strings, convert between types, validate passwords with custom rules, easily format dates and much more.


Package Files

array.go complex-string.go convert.go datetime.go email.go env.go filters.go handy.go handydatetime-translations.go handytranslations.go http.go inarray.go name.go password.go random-numeric-string.go random-string.go random.go region-bra.go reshape.go transform.go


const (
    // CheckStrAllowEmpty allows empty string ""
    CheckStrAllowEmpty = 1
    // CheckStrDenySpaces forbids spaces, tabs, new lines and carriage return
    CheckStrDenySpaces = 2
    // CheckStrDenyNumbers forbids digits/numbers
    CheckStrDenyNumbers = 4
    // CheckStrDenyLetters forbids letters
    CheckStrDenyLetters = 8
    // CheckStrDenySymbols forbids symbols. if it's not a number, letter or space, is considered a symbol
    CheckStrDenySymbols = 16
    // CheckStrDenyMoreThanOneWord forbids more than one word
    CheckStrDenyMoreThanOneWord = 32
    // CheckStrDenyUpperCase forbids uppercase letters
    CheckStrDenyUpperCase = 64
    // CheckStrDenyLowercase forbids lowercase letters
    CheckStrDenyLowercase = 128
    // CheckStrDenyUnicode forbids non-ASCII characters
    CheckStrDenyUnicode = 256
    // CheckStrRequireNumbers demands at least 1 number within string
    CheckStrRequireNumbers = 512
    // CheckStrRequireLetters demands at least 1 letter within string
    CheckStrRequireLetters = 1024
    // CheckStrRequireSymbols demands at least 1 symbol within string. if it's not a number, letter or space, is considered a symbol
    CheckStrRequireSymbols = 2048
    // CheckStrRequireMoreThanOneWord demands at least 2 words in given string input
    CheckStrRequireMoreThanOneWord = 4096
    // CheckStrRequireUpperCase demands at least 1 uppercase letter within string
    CheckStrRequireUpperCase = 8192
    // CheckStrRequireLowercase demands at least 1 lowercase letter within string
    CheckStrRequireLowercase = 16384

    // CheckStrOk means "alright"
    CheckStrOk = 0
    // CheckStrEmptyDenied is self explained
    CheckStrEmptyDenied = -1
    // CheckStrTooShort is self explained
    CheckStrTooShort = -2
    // CheckStrTooLong is self explained
    CheckStrTooLong = -4
    // CheckStrSpaceDenied is self explained
    CheckStrSpaceDenied = -5
    // CheckStrNubersDenied is self explained
    CheckStrNubersDenied = -6
    // CheckStrLettersDenied is self explained
    CheckStrLettersDenied = -7
    // CheckStrSymbolsDenied is self explained
    CheckStrSymbolsDenied = -8
    // CheckStrMoreThanOneWordDenied is self explained
    CheckStrMoreThanOneWordDenied = -9
    // CheckStrUpperCaseDenied is self explained
    CheckStrUpperCaseDenied = -10
    // CheckStrLowercaseDenied is self explained
    CheckStrLowercaseDenied = -11
    // CheckStrUnicodeDenied is self explained
    CheckStrUnicodeDenied = -12

    // CheckStrNumbersNotFound is self explained
    CheckStrNumbersNotFound = -13
    // CheckStrLettersNotFound is self explained
    CheckStrLettersNotFound = -14
    // CheckStrSymbolsNotFound is self explained
    CheckStrSymbolsNotFound = -15
    // CheckStrMoreThanOneWordNotFound is self explained
    CheckStrMoreThanOneWordNotFound = -16
    // CheckStrUpperCaseNotFound is self explained
    CheckStrUpperCaseNotFound = -17
    // CheckStrLowercaseNotFound is self explained
    CheckStrLowercaseNotFound = -18
const (
    // CheckPersonNameResultOK means the name was validated
    CheckPersonNameResultOK = 0
    // CheckPersonNameResultPolluted The routine only accepts letters, single quotes and spaces
    CheckPersonNameResultPolluted = 1
    // CheckPersonNameResultTooFewWords The funcion requires at least 2 words
    CheckPersonNameResultTooFewWords = 2
    // CheckPersonNameResultTooShort the sum of all characters must be >= 6
    CheckPersonNameResultTooShort = 3
    // CheckPersonNameResultTooSimple The name rule requires that at least one word
    CheckPersonNameResultTooSimple = 4
const (

    // CheckNewPasswordResultOK Means the checking ran alright
    CheckNewPasswordResultOK = 0
    // CheckNewPasswordResultDivergent Password is different from confirmation
    CheckNewPasswordResultDivergent = 1
    // CheckNewPasswordResultTooShort Password is too short
    CheckNewPasswordResultTooShort = 2
    // CheckNewPasswordResultTooSimple Given string doesn't satisfy complexity rules
    CheckNewPasswordResultTooSimple = 3

    // CheckNewPasswordComplexityLowest There's no rules besides the minimum length
    // >>> This flag turns all others off <<<
    CheckNewPasswordComplexityLowest = 1
    // CheckNewPasswordComplexityRequireLetter At least one letter is required in order to aprove password
    CheckNewPasswordComplexityRequireLetter = 2
    // CheckNewPasswordComplexityRequireUpperCase At least one uppercase letter is required in order to aprove password.
    // Only works if CheckNewPasswordComplexityRequireLetter is included/activated
    CheckNewPasswordComplexityRequireUpperCase = 4
    // CheckNewPasswordComplexityRequireNumber At least one number is required in order to aprove password
    CheckNewPasswordComplexityRequireNumber = 8
    // CheckNewPasswordComplexityRequireSpace The password must contain at least one space
    CheckNewPasswordComplexityRequireSpace = 16
    // CheckNewPasswordComplexityRequireSymbol User have to include at least one special character, like # or -
    CheckNewPasswordComplexityRequireSymbol = 32
const (
    // TransformNone No transformations are ordered. Only constraints maximum length
    // TransformNone turns all other flags OFF.
    TransformNone = 1
    // TransformFlagTrim Trim spaces before and after process the input
    // TransformFlagTrim Trims the string, removing leading and trailing spaces
    TransformFlagTrim = 2
    // TransformFlagLowerCase Makes the string lowercase
    // If case transformation flags are combined, the last one remains, considering the following order: TransformFlagTitleCase, TransformFlagLowerCase and TransformFlagUpperCase.
    TransformFlagLowerCase = 4
    // TransformFlagUpperCase Makes the string uppercase
    // If case transformation flags are combined, the last one remains, considering the following order: TransformFlagTitleCase, TransformFlagLowerCase and TransformFlagUpperCase.
    TransformFlagUpperCase = 8
    // TransformFlagOnlyDigits Removes all non-numeric characters
    TransformFlagOnlyDigits = 16
    // TransformFlagOnlyLetters Removes all non-letter characters
    TransformFlagOnlyLetters = 32
    // TransformFlagOnlyLettersAndDigits Leaves only letters and numbers
    TransformFlagOnlyLettersAndDigits = 64
    // TransformFlagHash After process all other flags, applies SHA256 hashing on string for output
    // 	The routine applies handy.StringHash() on given string
    TransformFlagHash = 128
    // TransformFlagTitleCase Makes the string uppercase
    // If case transformation flags are combined, the last one remains, considering the following order: TransformFlagTitleCase, TransformFlagLowerCase and TransformFlagUpperCase.
    TransformFlagTitleCase = 256
    // TransformFlagRemoveDigits Removes all digit characters, without to touch on any other
    // If combined with TransformFlagOnlyLettersAndDigits, TransformFlagOnlyDigits or TransformFlagOnlyLetters, it's ineffective
    TransformFlagRemoveDigits = 512

func AmountAsWord Uses

func AmountAsWord(n int64) string

AmountAsWord receives an int64 e returns the value as its text representation Today I have only the PT-BR text. Ex: AmountAsWord(129) => "cento e vinte e nove" Supports up to one trillion and does not add commas.

func ArrayDifference Uses

func ArrayDifference(a, b []int) []int

ArrayDifference returns all items that doesn't exist in both given arrays

func ArrayDifferenceAtoB Uses

func ArrayDifferenceAtoB(a, b []int) []int

ArrayDifferenceAtoB returns the items from A that doesn't exist in B

func Between Uses

func Between(n, low, high int) bool

Between checks if param n in between low and high integer params

func Bit Uses

func Bit(x interface{}) uint8

Bit returns only uint8(0) or uint8(1). It receives an interface, and when it's a number, and when this number is 0 (zero) it returns 0. Otherwise it returns 1 (one) If the interface is not a number, it returns 0 (zero)

func Boolean Uses

func Boolean(x interface{}) bool

Boolean returns the bool version/interpretation of some value; It receives an interface, and when this is a number, Boolean() returns flase of zero and true for different from zero. If it's a string, try to find "1", "T", "TRUE" to return true. Any other case returns false

func CheckCNPJ Uses

func CheckCNPJ(cnpj string) bool

CheckCNPJ returns true if the cnpj is valid Thanks to https://gopher.net.br/validacao-de-cpf-e-cnpj-em-go/ CNPJ is the Brazilian TAXPayerID document for companies

func CheckCPF Uses

func CheckCPF(cpf string) bool

CheckCPF returns true if the given input is a valid cpf CPF is the Brazilian TAXPayerID document for persons

func CheckDate Uses

func CheckDate(format, dateTime string) bool

CheckDate validates a date using the given format

func CheckDateYMD Uses

func CheckDateYMD(yyyymmdd string) bool

CheckDateYMD returns true if given input is a valid date in format yyyymmdd The function removes non-digit characters like "yyyy/mm/dd" or "yyyy-mm-dd", filtering to "yyyymmdd"

func CheckEmail Uses

func CheckEmail(email string) bool

CheckEmail returns true if the given input is a valid email address Observe that CheckEmail doesn't trim nor sanitize string before check See https://tools.ietf.org/html/rfc2822#section-3.4.1 for details about email address anatomy

func CheckMinLen Uses

func CheckMinLen(value string, minLength int) bool

CheckMinLen verifies if the rune-count is greater then or equal the given minimum It returns true if the given string has length greater than or equal than minLength parameter

func CheckNewPassword Uses

func CheckNewPassword(password, passwordConfirmation string, minimumlength uint, flagComplexity uint8) uint8

CheckNewPassword Run some basic checks on new password strings, based on given options This routine requires at least 4 (four) characters Example requiring only basic minimum length: CheckNewPassword("lalala", "lalala", 10, CheckNewPasswordComplexityLowest) Example requiring number and symbol: CheckNewPassword("lalala", "lalala", 10, CheckNewPasswordComplexityRequireNumber|CheckNewPasswordComplexityRequireSymbol)

func CheckNewPasswordResult Uses

func CheckNewPasswordResult(idiom string, r uint8) string

CheckNewPasswordResult returns a meaningful message describing the code generated bu CheckNewPassword() The routine considers the given idiom. The fallback is in english

func CheckPersonName Uses

func CheckPersonName(name string, acceptEmpty bool) uint8

CheckPersonName returns true if the name contains at least two words, one >= 3 chars and one >=2 chars. I understand that this is a particular criteria, but this is the OpenSourceMagic, where you can change and adapt to your own specs.

func CheckPersonNameResult Uses

func CheckPersonNameResult(idiom string, r uint8) string

CheckPersonNameResult returns a meaningful message describing the code generated bu CheckPersonName The routine considers the given idiom. The fallback is in english

func CheckPhone Uses

func CheckPhone(phone string, acceptEmpty bool) bool

CheckPhone returns true if a given input has between 9 and 14 digits

func CheckStr Uses

func CheckStr(seq string, minLen, maxLen uint, rules uint64) int8

CheckStr validates a string according given complexity rules CheckStr first evaluates "Deny" rules, and then "Require" rules. minLen=0 means there's no minimum length maxLen=0 means there's no maximum length

func CleanSpaces Uses

func CleanSpaces(s string) string

CleanSpaces removes duplicated spaces, tabs and newLine characters and then trim string's both sides

func DateReformat Uses

func DateReformat(dt1 string, currentFormat, newFormat string) string

DateReformat gets a date string in a given currentFormat, and transform it according newFormat

func DateStrCheckErrMessage Uses

func DateStrCheckErrMessage(idiom string, errCode DateStrCheck) string

DateStrCheckErrMessage translates the given error code into a plain string message

func DateTimeAsString Uses

func DateTimeAsString(dt time.Time, format string) string

DateTimeAsString formats time.Time variables as strings, considering the format directive

func DedupSpaces Uses

func DedupSpaces(s string) string

DedupSpaces removes duplicated spaces, tabs and newLine characters I.E: Replaces two tabs for one single tab

func ElapsedMonths Uses

func ElapsedMonths(from, to time.Time) int

ElapsedMonths returns the number of elapsed months between two given dates

func ElapsedTime Uses

func ElapsedTime(dtx, dty time.Time) (int, int, int, int, int, int)

ElapsedTime returns difference between two dates in years, months, days, hours, monutes and seconds Thanks to icza@https://stackoverflow.com/a/36531443/1301019

func ElapsedYears Uses

func ElapsedYears(from, to time.Time) int

ElapsedYears returns the number of elapsed years between two given dates

func EnvBool Uses

func EnvBool(key string, defaultValue bool) bool

EnvBool returns the env var value as boolean

func EnvCheck Uses

func EnvCheck(varName, defaultValue string, mandatory, debugPrint bool) error

EnvCheck Test environment variables

func EnvCheckMany Uses

func EnvCheckMany(envCheckers []EnvChecker) error

EnvCheckMany Test multiple environment variables at once

func EnvFloat64 Uses

func EnvFloat64(key string, defaultValue float64) float64

EnvFloat64 returns the env var value as float64

func EnvInt Uses

func EnvInt(key string, defaultValue int) int

EnvInt returns the env var value as int

func EnvInt64 Uses

func EnvInt64(key string, defaultValue int64) int64

EnvInt64 returns the env var value as int64

func EnvIntS Uses

func EnvIntS(key, separator string, defaultValue []int) []int

EnvIntS returns the env var value as []int

func EnvLoadFromDisk Uses

func EnvLoadFromDisk(fileName string, mustHave, overwriteValues bool) error

EnvLoadFromDisk loads a file from disk, containing variables written in KEY=VALUE format fileName is the file name with complete path mustHave forces an error if the file doesn't exist overwriteValue when false, makes the engine skip env vars that are already definied

func EnvStr Uses

func EnvStr(key, defaultValue string) string

EnvStr returns the env var value as string

func EnvStrS Uses

func EnvStrS(key, separator string, defaultValue []string) []string

EnvStrS returns the env var value as []string (string slice)

func HTTPAnswerJSON Uses

func HTTPAnswerJSON(w http.ResponseWriter, data interface{}) error

HTTPAnswerJSON converts the given data as json, set the content-type header and write it to requester

func HTTPJSONBodyToStruct Uses

func HTTPJSONBodyToStruct(r *http.Request, targetStruct interface{}) bool

HTTPJSONBodyToStruct decode json to a given anatomically compatible struct THIS ROUTINE IS BEEN DEPRECATED. Use HTTPJSONToStruct() instead.

func HTTPJSONToStruct Uses

func HTTPJSONToStruct(r *http.Request, targetStruct interface{}, closeBody bool) error

HTTPJSONToStruct decode json to a given anatomically compatible struct the differences to HTTPJSONBodyToStruct is that: - HTTPJSONToStruct can condittionally close body after unmarshalling - HTTPJSONToStruct returns an error instead of a bool

func HTTPRequestAsFloat64 Uses

func HTTPRequestAsFloat64(r *http.Request, key string, decimalSeparator rune) float64

HTTPRequestAsFloat64 gets a parameter coming from a http request as float64 number You have to inform the decimal separator symbol. If decimalSeparator is period, engine considers thousandSeparator is comma, and vice-versa.

func HTTPRequestAsInteger Uses

func HTTPRequestAsInteger(r *http.Request, key string) int

HTTPRequestAsInteger gets a parameter coming from a http request as an integer It tries to guess if it's a signed/negative integer

func HTTPRequestAsString Uses

func HTTPRequestAsString(r *http.Request, key string, maxLength int, transformOptions ...uint) string

HTTPRequestAsString gets a parameter coming from a http request as string, truncated to maxLength Only maxLength >= 1 is considered. Otherwise, it's ignored

func HasLetter Uses

func HasLetter(s string) bool

HasLetter returns true if input string contains at least one letter

func HasNumber Uses

func HasNumber(s string) bool

HasNumber returns true if input string contains at least one digit/number

func HasOnlyDigits Uses

func HasOnlyDigits(sequence string) bool

HasOnlyDigits returns true if the input is entirely numeric HasOnlyDigits is an alias for HasOnlyNumbers()

func HasOnlyLetters Uses

func HasOnlyLetters(sequence string) bool

HasOnlyLetters returns true if the input is entirely composed by letters

func HasOnlyNumbers Uses

func HasOnlyNumbers(sequence string) bool

HasOnlyNumbers returns true if the input is entirely numeric

func HasSymbol Uses

func HasSymbol(s string) bool

HasSymbol returns true if input string contains at least one symbol If rune is not a space, letter nor a number, it's considered a symbol

func InArray Uses

func InArray(array interface{}, item interface{}) bool

InArray searches for "item" in "array" and returns true if it's found This func resides here alone only because its long size. TODO Embrace/comprise all native scalar/primitive types

func InArrayIntFlex Uses

func InArrayIntFlex(item interface{}, array interface{}) bool

InArrayIntFlex returns true if "item" exists in "array" item and array can be of different kinds, since they're integer types array param should be an array of any integer type (int,int8,int16,int32,int64,uint,uint8,uint16,uint32 and uint64) The function uses bigInt type convertions previous to values comparison

func IsNumericType Uses

func IsNumericType(x interface{}) bool

IsNumericType checks if an interface's concrete type corresponds to some of golang native numeric types

func MatchesAny Uses

func MatchesAny(search interface{}, items ...interface{}) bool

MatchesAny returns true if any of the given items matches ( equals ) the subject ( search parameter )

func MonthLastDay Uses

func MonthLastDay(year int, month int) int

MonthLastDay returns the last day of month, considering the year for cover february in leap years Month is one-based, then january=1 If month is different of 2 (february) year is ignored Of month is february, year have to be valid

func NameFirst Uses

func NameFirst(name string, transformFlags uint) string

NameFirst returns the first word/name from the given input, optionally transformed by transformFlags Example: handy.NameFirst("friedrich wilhelm nietzsche", handy.TransformFlagTitleCase) // returns "Friedrich"

func NameFirstAndLast Uses

func NameFirstAndLast(name string, transformFlags uint) string

NameFirstAndLast returns the first and last words/names from the given input, optionally transformed by transformFlags Example: handy.NameFirstAndLast("friedrich wilhelm nietzsche", handy.TransformFlagTitleCase) // returns "Friedrich Nietzsche"

func NameInitials Uses

func NameInitials(name string, transformFlags uint) string

NameInitials returns the first and last words/names from the given input, optionally transformed by transformFlags

func NowAsString Uses

func NowAsString(format string) string

NowAsString formats time.Now() as string, considering the format directive

func OnlyDigits Uses

func OnlyDigits(sequence string) string

OnlyDigits returns only the numbers from the given string, after strip all the rest ( letters, spaces, etc. )

func OnlyLetters Uses

func OnlyLetters(sequence string) string

OnlyLetters returns only the letters from the given string, after strip all the rest ( numbers, spaces, etc. )

func OnlyLettersAndNumbers Uses

func OnlyLettersAndNumbers(sequence string) string

OnlyLettersAndNumbers returns only the letters and numbers from the given string, after strip all the rest, like spaces and special symbols.

func PositiveOrZero Uses

func PositiveOrZero(n int) int

PositiveOrZero checks if a signed number is negative, and in this case returns zero.

func RandomInt Uses

func RandomInt(min, max int) int

RandomInt returns a random integer within the given (inclusive) range

func RandomIntArray Uses

func RandomIntArray(min, max, howMany int) []int

RandomIntArray returns an array filled with random integer numbers

func RandomNumericString Uses

func RandomNumericString(forbiddenDigits []int, lengthMin, lengthMax int) string

RandomNumericString returns a string with length between given lengthMin and lengthMax Any digit within forbiddenDigits param will be ignored Example: https://play.golang.org/p/phF-y9ZsUIP

func RandomReseed Uses

func RandomReseed(min, max int) int

RandomReseed restarts the randonSeeder and returns a random integer within the given (inclusive) range

func RandomString Uses

func RandomString(minLen, maxLen int, allowUnicode, allowNumbers, allowSymbols, allowSpaces bool) string

RandomString generates a string sequence based on given params/rules

func RemoveDigits Uses

func RemoveDigits(sequence string) string

RemoveDigits returns the given string without digit/numeric runes

func Reshape Uses

func Reshape(format, sequence string) string

Reshape formats a string according "hash" positional directives Example: Reshape("#####-###","98765432") returns "98765-432" Example: Reshape("####.####-####/##","98765432101234") returns "9876.5432-1012/34" It tries to adapt the format to the sequence when the sizes doesn't match Example: Reshape("###.###.##","9876") returns "987.6" Example: Reshape("###.###","123456789") returns "123.456789" Run: https://play.golang.org/p/hlCyVZehTn3

func ReshapePH Uses

func ReshapePH(placeholder rune, format, sequence string) string

ReshapePH formats a string according positional directives given with an arbitrary placeholder It's the core of Reshape

func Reverse Uses

func Reverse(s string) string

Reverse returns the given string written backwards, with letters reversed.

func RuneHasSymbol Uses

func RuneHasSymbol(ru rune) bool

RuneHasSymbol returns true if the given rune contains a symbol

func StrContainsEmail Uses

func StrContainsEmail(seq string) bool

StrContainsEmail returns true if given string contains an email address

func StringAsDateTime Uses

func StringAsDateTime(s string, format string) time.Time

StringAsDateTime formats time.Time variables as strings, considering the format directive

func StringAsFloat Uses

func StringAsFloat(s string, decimalSeparator, thousandsSeparator rune) float64

StringAsFloat tries to convert a string to float, and if it can't, just returns zero It's limited to one billion

func StringAsInteger Uses

func StringAsInteger(s string) int

StringAsInteger returns the integer value extracted from string, or zero

func StringHash Uses

func StringHash(s string) string

StringHash simply generates a SHA256 hash from the given string In case of error, return ""

func StringReplaceAll Uses

func StringReplaceAll(original string, replacementPairs ...string) string

StringReplaceAll keeps replacing until there's no more ocurrences to replace.

func Tif Uses

func Tif(condition bool, tifThen, tifElse interface{}) interface{}

Tif is a simple implementation of the dear ternary IF operator

func Today Uses

func Today() (time.Time, string)

Today returns today's date at zero hours, minutes, seconds, etc. It returns a time and a yyyy-mm-dd formated string

func Todayf Uses

func Todayf(format string) (time.Time, string)

Todayf returns today's date at zero hours, minutes, seconds, etc. It returns a time and a custom formated string

func Transform Uses

func Transform(s string, maxLen int, transformFlags uint) string

Transform handles a string according given flags/parametrization, as follows: The transformations are made in arbitrary order, what can result in unexpected output. It the input matters, use TransformSerially instead. If maxLen==0, truncation is skipped The last operations are, by order, truncation and trimming.

func TransformSerially Uses

func TransformSerially(s string, maxLen int, transformFlags ...uint) string

TransformSerially reformat given string according parameters, in the order these params were sent Example: TransformSerially("uh lalah 123", 4, TransformFlagOnlyDigits,TransformFlagHash,TransformFlagUpperCase)

First remove non-digits, then hashes string and after make it all uppercase.

If maxLen==0, truncation is skipped Truncation is the last operation

func TrimLen Uses

func TrimLen(text string) int

TrimLen returns the runes count after trim the spaces

func Truncate Uses

func Truncate(s string, maxLen int, trim bool) string

Truncate limits the length of a given string, trimming or not, according parameters

func YMD Uses

func YMD() (int, int, int)

YMD returns today's date tokenized as year, month and day of month

func YMDasDate Uses

func YMDasDate(yyyymmdd string) (time.Time, error)

YMDasDate returns a valid time from the given yyymmdd-formatted input

func YMDasDateUTC Uses

func YMDasDateUTC(yyyymmdd string, utc bool) (time.Time, error)

YMDasDateUTC returns a valid UTC time from the given yyymmdd-formatted input

func YearsAge Uses

func YearsAge(birthdate time.Time) int

YearsAge returns the number of years past since a given date

type DateStrCheck Uses

type DateStrCheck uint8

DateStrCheck holds return status code of DateStrCheck functions

const (
    // DateStrCheckOk indicates an alright result
    DateStrCheckOk DateStrCheck = 0
    // DateStrCheckErrInvalid indicates the date is not valid
    DateStrCheckErrInvalid DateStrCheck = 1
    // DateStrCheckErrOutOfRange indicates the date is out of the supported range
    DateStrCheckErrOutOfRange DateStrCheck = 2
    // DateStrCheckErrEmpty indicates the date string is empty
    DateStrCheckErrEmpty DateStrCheck = 3

func DateStrCheckAge Uses

func DateStrCheckAge(date, format string, yearsAgeMin, yearsAgeMax int, acceptEmpty bool) DateStrCheck

DateStrCheckAge checks a date string considering minimum and maximum age The resulting code can be translated to text, according prefered idiom, with DateStrCheckErrMessage

func DateStrCheckRange Uses

func DateStrCheckRange(date, format string, dateMin, dateMax time.Time, acceptEmpty bool) DateStrCheck

DateStrCheckRange checks a date string considering minimum and maximum date range The resulting code can be translated to text, according prefered idiom, with DateStrCheckErrMessage

type EnvChecker Uses

type EnvChecker struct {
    VarName      string
    DefaultValue string
    Mandatory    bool
    DebugPrint   bool

EnvChecker holds instructions to assert an environment variable

func EnvCheckerNew Uses

func EnvCheckerNew(varName, defaultValue string, mandatory, debugPrint bool) EnvChecker

EnvCheckerNew returns a new instance of EnvChecker to be used with EnvCheckMany()

Package handy imports 15 packages (graph). Updated 2020-09-30. Refresh now. Tools for package owners.