helper

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2020 License: Apache-2.0 Imports: 20 Imported by: 22

README

common

Common helper utilities and wrappers for code reuse.

When we code projects, we constantly encounter a similar set of functionality and logic. This package's intent is to wrap those commonly recurring functionalities and access points into a reusable helper package, so that we don't have to keep maintaining separate code bases.

This package will continue to be updated with more reusable code as well.

types of helpers

  • string helpers
  • number helpers
  • io helpers
  • converter helpers
  • db type helpers
  • net helpers
  • reflection helpers
  • regex helpers
  • time and date helpers
  • uuid helpers
  • crypto helpers (aes, gcm, rsa, sha, etc)
  • csv parser helpers
  • wrappers for aws related services
    • service discovery / cloud map wrapper (using aws sdk)
    • dynamodb / dax wrapper (using aws sdk)
    • kms wrapper (using aws sdk)
    • redis wrapper (using go-redis package)
    • s3 wrapper (using aws sdk)
    • ses wrapper (using aws sdk)
    • sns wrapper (using aws sdk)
  • wrappers for relational database access
    • mysql wrapper (using sqlx package)
    • sqlite wrapper (using sqlx package)
    • sqlserver wrapper (using sqlx package)
  • other wrappers
    • for running as systemd service
    • for logging and config
    • for circuit breaker and rate limit
    • etc.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Atob

func Atob(s string) bool

Atob converts string to bool

func Atoi

func Atoi(s string) int

Atoi converts string to integer

func Base64StdDecode

func Base64StdDecode(data string) (string, error)

Base64StdDecode will decode given data from base 64 standard encoded string

func Base64StdEncode

func Base64StdEncode(data string) string

Base64StdEncode will encode given data into base 64 standard encoded string

func Base64UrlDecode

func Base64UrlDecode(data string) (string, error)

Base64UrlDecode will decode given data from base 64 url encoded string

func Base64UrlEncode

func Base64UrlEncode(data string) string

Base64UrlEncode will encode given data into base 64 url encoded string

func BoolPtrToBool

func BoolPtrToBool(b *bool) bool

BoolPtrToBool converts bool pointer to bool value

func BoolToInt

func BoolToInt(b bool) int

BoolToInt converts bool to int value

func Btoa

func Btoa(b bool) string

Btoa converts bool to string

func ByteToHex

func ByteToHex(data []byte) string

ByteToHex converts byte array into hex

func CopyDir

func CopyDir(src string, dst string) error

CopyDir - Dir copies a whole directory recursively

func CopyFile

func CopyFile(src string, dst string) error

CopyFile - File copies a single file from src to dst

func CurrentDate

func CurrentDate() string

CurrentDate returns current date in yyyy-mm-dd format

func CurrentDateStruct

func CurrentDateStruct() time.Time

CurrentDateStruct returns current date in yyyy-mm-dd format via time.Time struct

func CurrentDateTime

func CurrentDateTime() string

CurrentDateTime returns current date and time in yyyy-mm-dd hh:mm:ss tt format

func CurrentDateTimeStruct

func CurrentDateTimeStruct() time.Time

CurrentDateTimeStruct returns current date and time in yyyy-mm-dd hh:mm:ss tt format via time.Time struct

func CurrentTime

func CurrentTime() string

CurrentTime returns current time in hh:mm:ss tt format

func DateAfter

func DateAfter(testDate time.Time, afterDate time.Time) bool

DateAfter checks if testDate is after the afterDate

func DateAfterOrEqual

func DateAfterOrEqual(testDate time.Time, afterEqualDate time.Time) bool

DateAfterOrEqual checks if testDate is after or equal to the afterEqualDate

func DateBefore

func DateBefore(testDate time.Time, beforeDate time.Time) bool

DateBefore checks if testDate is before the beforeDate

func DateBeforeOrEqual

func DateBeforeOrEqual(testDate time.Time, beforeEqualDate time.Time) bool

DateBeforeOrEqual checks if testDate is before or equal to the beforeEqualDate

func DateBetween

func DateBetween(testDate time.Time, fromDate time.Time, toDate time.Time, doNotIncludeEqual bool) bool

DateBetween checks if testDate is within the fromDate and toDate, if doNotIncludeEqual = true, then testDate equals fromDate and toDate are skipped

func DateEqual

func DateEqual(testDate time.Time, equalDate time.Time) bool

DateEqual checks if the testDate equals to the equalDate

func DateFormatString

func DateFormatString() string

DateFormatString returns the date format string constant (yyyy-mm-dd)

func DateOutside

func DateOutside(testDate time.Time, fromDate time.Time, toDate time.Time) bool

DateOutside checks if the testDate is outside of the fromDate and toDate

func DatePtrToString

func DatePtrToString(t *time.Time) string

DatePtrToString formats pointer time.Time to string date format

func DateTimeFormatString

func DateTimeFormatString() string

DateTimeFormatString returns the date time format string constant (yyyy-mm-dd hh:mm:ss tt)

func DateTimePtrToDateTime

func DateTimePtrToDateTime(t *time.Time) time.Time

DateTimePtrToDateTime formats pointer time.Time to time.Time struct

func DateTimePtrToString

func DateTimePtrToString(t *time.Time) string

DateTimePtrToString formats pointer time.Time to string date time format

func DateToLocal

func DateToLocal(t time.Time) (time.Time, error)

DateToLocal converts given time to local time

func DateToLocal2

func DateToLocal2(t time.Time) time.Time

DateToLocal2 returns local value directly without error info

func DateToUTC

func DateToUTC(t time.Time) (time.Time, error)

DateToUTC converts given time to utc

func DateToUTC2

func DateToUTC2(t time.Time) time.Time

DateToUTC2 returns utc value directly without error info

func DaysDiff

func DaysDiff(timeFrom time.Time, timeTo time.Time) int

DaysDiff gets the days difference between from and to date

func DnsLookupIps

func DnsLookupIps(host string) (ipList []net.IP)

DnsLookupIps returns list of IPs for the given host if host is private on aws route 53, then lookup ip will work only when within given aws vpc that host was registered with

func DnsLookupSrvs

func DnsLookupSrvs(host string) (ipList []string)

DnsLookupSrvs returns list of IP and port addresses based on host if host is private on aws route 53, then lookup ip will work only when within given aws vpc that host was registered with

func DurationPtr

func DurationPtr(d time.Duration) *time.Duration

DurationPtr casts Duration to Duration pointer

func ExtractAlphaNumeric

func ExtractAlphaNumeric(s string) (string, error)

ExtractAlphaNumeric will extract only A-Z, a-z, and 0-9 out of string to be returned

func ExtractNumeric

func ExtractNumeric(s string) (string, error)

ExtractNumeric will extract only 0-9 out of string to be returned

func FileExists

func FileExists(path string) bool

FileExists checks if input file in path exists

func FileRead

func FileRead(path string) (string, error)

FileRead will read all file content of given file in path, return as string if successful, if failed, error will contain the error reason

func FileWrite

func FileWrite(path string, data string) error

FileWrite will write data into file at the given path, if succesful, no error is returned (nil)

func Float32Ptr

func Float32Ptr(f float32) *float32

Float32Ptr casts float32 to float32 pointer

func Float32PtrToFloat32

func Float32PtrToFloat32(f *float32) float32

Float32PtrToFloat32 returns 0 if nil, otherwise actual float32 value

func Float32ToString

func Float32ToString(f float32) string

Float32ToString converts float32 into string value

func Float32ToStringCents

func Float32ToStringCents(f float32) string

Float32ToStringCents converts float32 into string representing cent values

func Float64Ptr

func Float64Ptr(f float64) *float64

Float64Ptr casts float64 to float64 pointer

func Float64PtrToFloat64

func Float64PtrToFloat64(f *float64) float64

Float64PtrToFloat64 returns 0 if nil, otherwise actual float64 value

func Float64ToInt

func Float64ToInt(f float64) int

Float64ToInt converts from float64 into int

func FloatToString

func FloatToString(f float64) string

FloatToString converts float64 into string value

func FormatDate

func FormatDate(t time.Time) string

FormatDate will format the input date value to yyyy-mm-dd

func FormatDateTime

func FormatDateTime(t time.Time) string

FormatDateTime will format the input date value to yyyy-mm-dd hh:mm:ss tt

func FormatDateTimeToMMDDYYYYhhmmss

func FormatDateTimeToMMDDYYYYhhmmss(t time.Time) string

FormatDateTimeToMMDDYYYYhhmmss for the date time struct received

func FormatDateTimeToYYYYMMDDhhmmss

func FormatDateTimeToYYYYMMDDhhmmss(t time.Time) string

FormatDateTimeToYYYYMMDDhhmmss for the date time struct received

func FormatDateToDDMMYYYY

func FormatDateToDDMMYYYY(t time.Time) string

FormatDateToDDMMYYYY for the date time struct received

func FormatDateToMMDD

func FormatDateToMMDD(t time.Time) string

FormatDateToMMDD for the date time struct received

func FormatDateToMMYY

func FormatDateToMMYY(t time.Time) string

FormatDateToMMYY for the date time struct received

func FormatDateToYYMM

func FormatDateToYYMM(t time.Time) string

FormatDateToYYMM for the date time struct received

func FormatDateToYYMMDD

func FormatDateToYYMMDD(t time.Time) string

FormatDateToYYMMDD for the date time struct received

func FormatDateToYYYYMMDD

func FormatDateToYYYYMMDD(t time.Time) string

FormatDateToYYYYMMDD for the date time struct received

func FormatTime

func FormatTime(t time.Time) string

FormatTime will format the input date value to hh:mm:ss tt

func FromNullBool

func FromNullBool(b sql.NullBool) bool

FromNullBool casts sql null bool variable to bool variable, if null, false is returned

func FromNullFloat32

func FromNullFloat32(d sql.NullFloat64) float32

FromNullFloat32 casts sql null float64 into float32 variable

func FromNullFloat64

func FromNullFloat64(d sql.NullFloat64) float64

FromNullFloat64 casts sql null float64 variable to float64 variable, if null, 0.00 is returned

func FromNullInt

func FromNullInt(d sql.NullInt32) int

FromNullInt casts sql NullInt32 into int variable, if null, 0 is returned

func FromNullInt64

func FromNullInt64(d sql.NullInt64) int64

FromNullInt64 casts sql null int64 variable to int64 variable, if null, 0 is returned

func FromNullString

func FromNullString(s sql.NullString) string

FromNullString casts sql null string variable to string variable, if null, blank string is returned

func FromNullTime

func FromNullTime(t sql.NullTime) time.Time

FromNullTime parses string into time.Time

func GenerateNewUniqueInt32

func GenerateNewUniqueInt32(oldIntVal int) int

GenerateNewUniqueInt32 will take in old value and return new unique value with randomized seed and negated

func GenerateNewUniqueInt64

func GenerateNewUniqueInt64(oldIntVal int64) int64

GenerateNewUniqueInt64 will take in old value and return new unique value with randomized seed and negated

func GenerateNewUniqueNullInt32

func GenerateNewUniqueNullInt32(oldIntVal sql.NullInt32) sql.NullInt32

GenerateNewUniqueNullInt32 will take in old value and return new unique value with randomized seed and negated

func GenerateNewUniqueNullInt64

func GenerateNewUniqueNullInt64(oldIntVal sql.NullInt64) sql.NullInt64

GenerateNewUniqueNullInt64 will take in old value and return new unique value with randomized seed and negated

func GenerateNewUniqueNullString

func GenerateNewUniqueNullString(oldStrVal sql.NullString, stringLimit int) sql.NullString

GenerateNewUniqueNullString will take in old value and return new unique value with randomized seed

stringLimit = 0 no limit, > 0 has limit

func GenerateNewUniqueString

func GenerateNewUniqueString(oldStrVal string, stringLimit int) string

GenerateNewUniqueString will take in old value and return new unique value with randomized seed

stringLimit = 0 no limit, > 0 has limit

func GenerateRandomChar

func GenerateRandomChar() string

GenerateRandomChar will create a random character, using unix nano as seed

func GenerateRandomNumber

func GenerateRandomNumber(maxNumber int) int

GenerateRandomNumber with unix nano as seed

func GenerateULID

func GenerateULID() (string, error)

GenerateULID will generate a ULID that is globally unique (very slim chance of collision)

func GenerateUUIDv4

func GenerateUUIDv4() (string, error)

GenerateUUIDv4 will generate a UUID Version 4 (Random) to represent a globally unique identifier (extremely rare chance of collision)

func GetFirstBoolOrDefault

func GetFirstBoolOrDefault(defaultValue bool, paramValue ...bool) bool

GetFirstBoolOrDefault will select the first variadic value from paramValue, if no paramValue variadic, then defaultValue is used as return value

func GetFirstByteOrDefault

func GetFirstByteOrDefault(defaultValue byte, paramValue ...byte) byte

GetFirstByteOrDefault will select the first variadic value from paramValue, if no paramValue variadic, then defaultValue is used as return value

func GetFirstFloat32OrDefault

func GetFirstFloat32OrDefault(defaultValue float32, paramValue ...float32) float32

GetFirstFloat32OrDefault will select the first variadic value from paramValue, if no paramValue variadic, then defaultValue is used as return value

func GetFirstFloat64OrDefault

func GetFirstFloat64OrDefault(defaultValue float64, paramValue ...float64) float64

GetFirstFloat64OrDefault will select the first variadic value from paramValue, if no paramValue variadic, then defaultValue is used as return value

func GetFirstInt64OrDefault

func GetFirstInt64OrDefault(defaultValue int64, paramValue ...int64) int64

GetFirstInt64OrDefault will select the first variadic value from paramValue, if no paramValue variadic, then defaultValue is used as return value

func GetFirstIntOrDefault

func GetFirstIntOrDefault(defaultValue int, paramValue ...int) int

GetFirstIntOrDefault will select the first variadic value from paramValue, if no paramValue variadic, then defaultValue is used as return value

func GetFirstOrDefault

func GetFirstOrDefault(defaultValue interface{}, paramValue ...interface{}) interface{}

GetFirstOrDefault will select the first variadic value from paramValue, if no paramValue variadic, then defaultValue is used as return value

func GetFirstStringOrDefault

func GetFirstStringOrDefault(defaultValue string, paramValue ...string) string

GetFirstStringOrDefault will select the first variadic value from paramValue, if no paramValue variadic, then defaultValue is used as return value

func GetFirstTimeOrDefault

func GetFirstTimeOrDefault(defaultValue time.Time, paramValue ...time.Time) time.Time

GetFirstTimeOrDefault will select the first variadic value from paramValue, if no paramValue variadic, then defaultValue is used as return value

func GetLocalIP

func GetLocalIP() string

GetLocalIP returns the first non loopback ip

func GetNetListener

func GetNetListener(port uint) (net.Listener, error)

GetNetListener triggers the specified port to listen via tcp

func GetStructTagValueByObject

func GetStructTagValueByObject(structObj interface{}, structFieldName string, structTagName string) (notFound bool, tagValue string, t reflect.Type)

GetStructTagValueByObject will accept a struct object, struct field name, and struct tag name, and return the found tag value and reflect type, if reflect type or struct tag is not found, a notFound is returned [ Parameters ]

structObj = struct object variable
structFieldName = struct's field name (CASE SENSITIVE)
structTagName = struct's tag name (the left side of struct tag - the key portion) (CASE SENSITIVE)

func GetStructTagValueByType

func GetStructTagValueByType(t reflect.Type, structFieldName string, structTagName string) (notFound bool, tagValue string)

GetStructTagValueByType will accept a prior obtained reflect type, struct field name, and struct tag name, and return the found tag value, if struct tag value is not found, a notFound is returned, if the reflect type is nil, then not found is returned too [ Parameters ]

t = reflect type of a struct object (obtained via GetStructTagValueByObject)
structFieldName = struct's field name (CASE SENSITIVE)
structTagName = struct's tag name (the left side of struct tag - the key portion) (CASE SENSITIVE)

func HTMLDecode

func HTMLDecode(s string) string

HTMLDecode will unescape html tags and extended tags relevant to our apps

func HTMLEncode

func HTMLEncode(s string) string

HTMLEncode will escape html tags

func HexToByte

func HexToByte(hexData string) ([]byte, error)

HexToByte converts hex data into byte array

func HexToString

func HexToString(hexData string) (string, error)

HexToString converts hex data into string

func HoursDiff

func HoursDiff(timeFrom time.Time, timeTo time.Time) int

HoursDiff gets the hours difference between from and to date

func Int32PtrToInt

func Int32PtrToInt(n *int) int

Int32PtrToInt returns 0 if nil, otherwise actual int value

func Int64Ptr

func Int64Ptr(i int64) *int64

Int64Ptr casts int64 to int64 pointer

func Int64PtrToInt64

func Int64PtrToInt64(n *int64) int64

Int64PtrToInt64 returns 0 if nil, otherwise actual int64 value

func Int64ToString

func Int64ToString(n int64) string

Int64ToString converts int64 into string value

func IntPtr

func IntPtr(i int) *int

IntPtr casts int to int pointer

func IsAlphanumericAndSpaceOnly

func IsAlphanumericAndSpaceOnly(s string) bool

IsAlphanumericAndSpaceOnly checks if the input string is A-Z, a-z, 0-9, and space

func IsAlphanumericOnly

func IsAlphanumericOnly(s string) bool

IsAlphanumericOnly checks if the input string is A-Z, a-z, and 0-9 only

func IsBase64Only

func IsBase64Only(s string) bool

IsBase64Only checks if the input string is a-z, A-Z, 0-9, +, /, =

func IsBool

func IsBool(s string) bool

IsBool tests if input string is boolean

func IsDayOfMonthValid

func IsDayOfMonthValid(year int, month int, day int) bool

IsDayOfMonthValid checks if the month day number is valid

func IsFloat32

func IsFloat32(s string) bool

IsFloat32 tests if input string is float 32 bit (decimal point value)

func IsFloat64

func IsFloat64(s string) bool

IsFloat64 tests if input string is float 64 bit (decimal point value)

func IsHexOnly

func IsHexOnly(s string) bool

IsHexOnly checks if the input string is a-f, A-F, 0-9

func IsInt32

func IsInt32(s string) bool

IsInt32 tests if input string is integer (whole numbers 32 bits)

func IsInt64

func IsInt64(s string) bool

IsInt64 tests if input string is big integer (whole number greater 64 bits)

func IsLeapYear

func IsLeapYear(year int) bool

IsLeapYear checks if the year input is leap year or not

func IsNumericIntAndNegativeSignOnly

func IsNumericIntAndNegativeSignOnly(s string) bool

IsNumericIntAndNegativeSignOnly checks if the input string is 0-9 and possibly with lead negative sign only

func IsNumericIntOnly

func IsNumericIntOnly(s string) bool

IsNumericIntOnly checks if the input string is 0-9 only

func Itoa

func Itoa(i int) string

Itoa converts integer into string

func Left

func Left(s string, l int) string

Left returns the left side of string indicated by variable l (size of substring)

func LenTrim

func LenTrim(s string) int

LenTrim returns length of space trimmed string s

func LenTrimNullString

func LenTrimNullString(s sql.NullString) int

LenTrimNullString returns string length

func MarshalJSONCompact

func MarshalJSONCompact(v interface{}) (string, error)

MarshalJSONCompact will accept an input variable, typically struct with json struct tags, to serialize from object into json string with compact formatting

*** STRUCT FIELDS MUST BE EXPORTED FOR MARSHAL AND UNMARSHAL ***

struct json tags:

`json:"ElementName"`								<<< JSON Element Name
`json:"...,omitempty"`							<<< Omit This Line if Empty Value (false, 0, nil, zero length array)
`json:"-"` <<< Omit From JSON Marshal

func MarshalJSONIndent

func MarshalJSONIndent(v interface{}) (string, error)

MarshalJSONIndent will accept an input variable, typically struct with json struct tags, to serialize from object into json string with indented formatting

*** STRUCT FIELDS MUST BE EXPORTED FOR MARSHAL AND UNMARSHAL ***

struct json tags:

`json:"ElementName"`								<<< JSON Element Name
`json:"...,omitempty"`							<<< Omit This Line if Empty Value (false, 0, nil, zero length array)
`json:"-"` <<< Omit From JSON Marshal

func MarshalXML

func MarshalXML(v interface{}, indentXML bool) (string, error)

MarshalXML with option for indent or compact

func MarshalXMLCompact

func MarshalXMLCompact(v interface{}) (string, error)

MarshalXMLCompact will accept an input variable, typically struct with xml struct tags, to serialize from object into xml string

*** STRUCT FIELDS MUST BE EXPORTED FOR MARSHAL AND UNMARSHAL ***

special struct field:

XMLName xml.Name `xml:"ElementName"`

struct xml tags:

`xml:"AttributeName,attr"` or `xml:",attr"` 		<<< Attribute Instead of Element
`xml:"ElementName"`								<<< XML Element Name
`xml:"OuterElementName>InnerElementName"` 		<<< Outer XML Grouping By OuterElementName
`xml:",cdata"`									<<< <![CDATA[...]]
`xml:",innerxml"`								    <<< Write as Inner XML Verbatim and Not Subject to Marshaling
`xml:",comment"`									<<< Write as Comment, and Not Contain "--" Within Value
`xml:"...,omitempty"`								<<< Omit This Line if Empty Value (false, 0, nil, zero length array)
`xml:"-"` <<< Omit From XML Marshal

func MarshalXMLIndent

func MarshalXMLIndent(v interface{}) (string, error)

MarshalXMLIndent will accept an input variable, typically struct with xml struct tags, to serialize from object into xml string with indented formatting

*** STRUCT FIELDS MUST BE EXPORTED FOR MARSHAL AND UNMARSHAL ***

special struct field:

XMLName xml.Name `xml:"ElementName"`

struct xml tags:

`xml:"AttributeName,attr"` or `xml:",attr"` 		<<< Attribute Instead of Element
`xml:"ElementName"`								<<< XML Element Name
`xml:"OuterElementName>InnerElementName"` 		<<< Outer XML Grouping By OuterElementName
`xml:",cdata"`									<<< <![CDATA[...]]
`xml:",innerxml"`								    <<< Write as Inner XML Verbatim and Not Subject to Marshaling
`xml:",comment"`									<<< Write as Comment, and Not Contain "--" Within Value
`xml:"...,omitempty"`								<<< Omit This Line if Empty Value (false, 0, nil, zero length array)
`xml:"-"` <<< Omit From XML Marshal

func Mid

func Mid(s string, start int, l int) string

Mid returns the middle of string indicated by variable start and l positions (size of substring)

func MinutesDiff

func MinutesDiff(timeFrom time.Time, timeTo time.Time) int

MinutesDiff gets the minutes difference between from and to date

func NewULID

func NewULID() string

NewULID will generate a new ULID and ignore error if any

func NewUUID

func NewUUID() string

NewUUID will generate a UUID Version 4 (Random) and ignore error if any

func NextFixedLength

func NextFixedLength(data string, blockSize int) int

NextFixedLength calculates the next fixed length total block size, for example, if block size is 16, then the total size should be 16, 32, 48 and so on based on data length

func PadLeft

func PadLeft(data string, totalSize int) string

PadLeft will pad data with space to the left

func PadRight

func PadRight(data string, totalSize int) string

PadRight will pad data with space to the right

func Padding

func Padding(data string, totalSize int, padRight bool, padChar string) string

Padding will pad the data with specified char either to the left or right

func ParseBool

func ParseBool(s string) (bool, bool)

ParseBool tests and parses if input string is boolean, return value 1st bool is the boolean result, return value 2nd bool is the ParseBool success or failure indicator

func ParseDate

func ParseDate(s string) time.Time

ParseDate will parse a date value in yyyy-mm-dd format into time.Time object, check time.IsZero() to verify if a zero time is returned indicating parser failure

func ParseDateFromDDMMYYYY

func ParseDateFromDDMMYYYY(s string) time.Time

ParseDateFromDDMMYYYY from string value

func ParseDateFromMMDD

func ParseDateFromMMDD(s string) time.Time

ParseDateFromMMDD from string value

func ParseDateFromMMYY

func ParseDateFromMMYY(s string) time.Time

ParseDateFromMMYY from string value

func ParseDateFromYYMM

func ParseDateFromYYMM(s string) time.Time

ParseDateFromYYMM from string value

func ParseDateFromYYMMDD

func ParseDateFromYYMMDD(s string) time.Time

ParseDateFromYYMMDD from string value

func ParseDateFromYYYYMMDD

func ParseDateFromYYYYMMDD(s string) time.Time

ParseDateFromYYYYMMDD from string value

func ParseDateTime

func ParseDateTime(s string) time.Time

ParseDateTime will parse a date time value in yyyy-mm-dd hh:mm:ss tt format into time.Time object, check time.IsZero() to verify if a zero time is returned indicating parser failure

func ParseDateTime24Hr

func ParseDateTime24Hr(s string) time.Time

ParseDateTime24Hr will parse a date time value in yyyy-mm-dd HH:mm:ss format into time.Time object, check time.IsZero() to verify if a zero time is returned indicating parser failure

func ParseDateTimeCustom

func ParseDateTimeCustom(s string, f string) time.Time

ParseDateTimeCustom will parse a date time value in s string, based on the f format f format is 2006 01 02 15:04:05 / 03:04:05 PM

func ParseDateTimeFromMMDDYYYYhhmmss

func ParseDateTimeFromMMDDYYYYhhmmss(s string) time.Time

ParseDateTimeFromMMDDYYYYhhmmss from string value

func ParseDateTimeFromYYYYMMDDhhmmss

func ParseDateTimeFromYYYYMMDDhhmmss(s string) time.Time

ParseDateTimeFromYYYYMMDDhhmmss from string value

func ParseDateToLastDayOfMonth

func ParseDateToLastDayOfMonth(t time.Time) time.Time

ParseDateToLastDayOfMonth

func ParseFloat32

func ParseFloat32(s string) (float32, bool)

ParseFloat32 tests and parses if input string is float 32 bit (decimal point value)

func ParseFloat64

func ParseFloat64(s string) (float64, bool)

ParseFloat64 tests and parses if input string is float 64 bit (decimal point value)

func ParseHostFromURL

func ParseHostFromURL(url string) string

ParseHostFromURL will parse out the host name from url

func ParseInt32

func ParseInt32(s string) (int, bool)

ParseInt32 tests and parses if input string is integer (whole numbers 32 bits)

func ParseInt64

func ParseInt64(s string) (int64, bool)

ParseInt64 tests and parses if input string is big integer (whole number greater 64 bits)

func ParseKeyValue

func ParseKeyValue(s string, delimiter string, key *string, val *string) error

ParseKeyValue will parse the input string using specified delimiter (= is default), result is set in the key and val fields

func ParseTime

func ParseTime(s string) time.Time

ParseTime will parse a time vaule in hh:mm:ss tt format into time.Time object, check time.IsZero() to verify if a zero time is returned indicating parser failure

func RegexReplaceSubString

func RegexReplaceSubString(source string, subStringFrom string, subStringTo string, replaceWith string, caseInsensitive bool) string

RegexReplaceSubString will search for substring between subStringFrom and subStringTo, replace with the replaceWith string, and optionally case insensitive or not

func Replace

func Replace(s string, oldChar string, newChar string) string

Replace will replace old char with new char and return the replaced string

func Reverse

func Reverse(s string) string

Reverse a string

func Right(s string, l int) string

Right returns the right side of string indicated by variable l (size of substring)

func RightTrimLF

func RightTrimLF(s string) string

RightTrimLF will remove linefeed (return char) from the right most char and return result string

func SecondsDiff

func SecondsDiff(timeFrom time.Time, timeTo time.Time) int

SecondsDiff gets the seconds difference between from and to date

func SliceObjectsToSliceInterface

func SliceObjectsToSliceInterface(objectsSlice interface{}) (output []interface{})

SliceObjectsToSliceInterfaces will convert slice of objects into slice of interfaces

func SplitString

func SplitString(source string, delimiter string, index int) string

SplitString will split the source string using delimiter, and return the element indicated by index, if nothing is found, blank is returned, index = -1 returns last index

func StrToUint

func StrToUint(s string) uint

StrToUint converts from string to uint

func StringPtr

func StringPtr(s string) *string

StringPtr casts string to string pointer

func StringPtrToString

func StringPtrToString(s *string) string

StringPtrToString gets string value from string pointer

func StringToHex

func StringToHex(data string) string

StringToHex converts string into hex

func TimeFormatString

func TimeFormatString() string

TimeFormatString returns the time format string constant (hh:mm:ss tt)

func TimePtr

func TimePtr(t time.Time) *time.Time

TimePtr casts Time to Time pointer

func ToNullBool

func ToNullBool(b bool) sql.NullBool

ToNullBool sets bool into NullBool output

func ToNullFloat32

func ToNullFloat32(d float32, emptyAsNull bool) sql.NullFloat64

ToNullFloat32 sets float32 into NullFloat64 output

func ToNullFloat64

func ToNullFloat64(d float64, emptyAsNull bool) sql.NullFloat64

ToNullFloat64 sets float64 into NullFloat64 output

func ToNullInt

func ToNullInt(d int, emptyAsNull bool) sql.NullInt32

ToNullInt sets int value into NullInt32 output

func ToNullInt64

func ToNullInt64(d int64, emptyAsNull bool) sql.NullInt64

ToNullInt64 sets int64 value into NullInt64 output

func ToNullString

func ToNullString(s string, emptyAsNull bool) sql.NullString

ToNullString sets string value into NullString output

func ToNullTime

func ToNullTime(t time.Time) sql.NullTime

ToNullTime sets time.Time into NullTime output

func Trim

func Trim(s string) string

Trim gets the left and right space trimmed input string s

func UInt64ToString

func UInt64ToString(n uint64) string

UInt64ToString converts uint64 into string value

func UintToStr

func UintToStr(i uint) string

UintToStr converts from uint to string

func UnmarshalJSON

func UnmarshalJSON(jsonData string, v interface{}) error

UnmarshalJSON will accept input json data string and deserialize into target object indicated by parameter v

*** PASS PARAMETER AS "&v" IN ORDER TO BE WRITABLE ***

*** STRUCT FIELDS MUST BE EXPORTED FOR MARSHAL AND UNMARSHAL ***

if unmarshal is successful, nil is returned, otherwise error info is returned

func UnmarshalXML

func UnmarshalXML(xmlData string, v interface{}) error

UnmarshalXML will accept input xml data string and deserialize into target object indicated by parameter v

*** PASS PARAMETER AS "&v" IN ORDER TO BE WRITABLE ***

*** STRUCT FIELDS MUST BE EXPORTED FOR MARSHAL AND UNMARSHAL ***

if unmarshal is successful, nil is returned, otherwise error info is returned

func XMLFromEscaped

func XMLFromEscaped(data string) string

XMLFromEscaped will un-escape the data whose &gt; &lt; &amp; &#37; &apos; &quot; are converted to > < & % ' "

func XMLToEscaped

func XMLToEscaped(data string) string

XMLToEscaped will escape the data whose xml special chars > < & % ' " are escaped into &gt; &lt; &amp; &#37; &apos; &quot;

Types

This section is empty.

Jump to

Keyboard shortcuts

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