utils

package module
v0.0.0-...-1e5144a Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: MIT Imports: 48 Imported by: 5

Documentation

Index

Constants

View Source
const (
	TimeISO8601LayOut     = "2006-01-02T15:04:05-0700"
	AUTimeLayout          = "02/01/2006 15:04:05 MST"
	CleanStringDateLayout = "2006-01-02-150405"
	LetterBytes           = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#%^()-,."
)

TimeISO8601LayOut

Variables

View Source
var GetMapByKey = LookupMap

GetMapByKey - we have LookupMap

View Source
var MapLookup = LookupMap

Functions

func Assert

func Assert(cond bool, msg string, fatal bool) bool

func BcryptCheckPasswordHash

func BcryptCheckPasswordHash(password, hash string) bool

func BcryptHashPassword

func BcryptHashPassword(password string, cost int) (string, error)

func CheckErr

func CheckErr(err error, location string)

func CheckErrNonFatal

func CheckErrNonFatal(err error, location string) error

func CheckNonErrIfMatch

func CheckNonErrIfMatch(err error, ptn, location string) error

func ChunkString

func ChunkString(s string, chunkSize int) []string

ChunkString -

func ComputeHash

func ComputeHash(plainText string, salt []byte) string

func ConfigureLogging

func ConfigureLogging(w *os.File)

func Curl

func Curl(method, url, data, savefilename string, headers []string) (string, error)

func Decrypt

func Decrypt(ciphertextBase64 string, key string) (string, error)

func Encrypt

func Encrypt(text, key string) string

func FileExists

func FileExists(name string) (bool, error)

func FileNameWithoutExtension

func FileNameWithoutExtension(fileName string) string

func FileTouch

func FileTouch(fileName string) error

func FindAndParseTemplates

func FindAndParseTemplates(rootDir, fileExtention string, funcMap template.FuncMap) (*template.Template, []string, error)

func Format

func Format(tmplStr string, data interface{}) string

func GenRandomString

func GenRandomString(n int) string

func GenRandomStringV2

func GenRandomStringV2(n int) string

func GenSelfSignedKey

func GenSelfSignedKey(keyfilename string)

func GetFormValue

func GetFormValue(r *http.Request, key ...string) string

GetFormValue -

func GetMuxValue

func GetMuxValue(r *http.Request, key ...string) string

GetMuxValue -

func GetQueryValue

func GetQueryValue(r *http.Request, key ...string) string

GetQueryValue -

func GetRandomNumberUseQrng

func GetRandomNumberUseQrng(length int) []int

OK seems ANU is too scared of abuse, even using with api key it still limit reqeust severely. Offer no so much value unless we need to buy? Yuk!

func GetRequestValue

func GetRequestValue(r *http.Request, key ...string) string

GetRequestValue - Attempt to get a val by key from the request in all cases. First from the mux variables in the route path such as /dosomething/{var1}/{var2} Then check the query string values such as /dosomething?var1=x&var2=y Then check the form values if any Then check the default value if supplied to use as return value For performance we split each type into each function so it can be called independantly

func Getenv

func Getenv(key, fallback string) string

func JsonDump

func JsonDump(obj interface{}, indent string) string

func JsonDumpByte

func JsonDumpByte(obj interface{}, indent string) []byte

func LoadConfigIntoEnv

func LoadConfigIntoEnv(configFile string) map[string]interface{}

func LookupMap

func LookupMap(m map[string]interface{}, key string, default_val interface{}) interface{}

func MakePassword

func MakePassword(length int) string

MakePassword -

func MakeRandNum

func MakeRandNum(max int) int

MakeRandNum -

func MakeRequest

func MakeRequest(method string, config map[string]interface{}, data []byte, jar *cookiejar.Jar) map[string]interface{}

func MakeSalt

func MakeSalt(length int8) (salt *[]byte)

func Md5Sum

func Md5Sum(key string) string

func MergeAttributes

func MergeAttributes(a, b []interface{}, action string) []interface{}

Add or delete attrbs set in a to b

func MustOpenFile

func MustOpenFile(f string) *os.File

func NsToTime

func NsToTime(ns int64) time.Time

NsToTime -

func ParseConfig

func ParseConfig(configFile string) map[string]interface{}

func ParseTimeRange

func ParseTimeRange(durationStr, tz string) (time.Time, time.Time)

Given a duration string return a tuple of start time, end time satisfy the duration. If duration string is dd/mm/yyyy hh:mm:ss - dd/mm/yyyy hh:mm:ss it simply return two time object. If duration is like 15m then endtime is now, start time is 15 minutes ago. This applies for all case if input is not parsable

func RandomHex

func RandomHex(n int) (string, error)

func ReadFileToBase64Content

func ReadFileToBase64Content(filename string) string

func RemoveDuplicate

func RemoveDuplicate(strSlice []interface{}) []interface{}

func RemoveDuplicateInt

func RemoveDuplicateInt(strSlice []int) []int

func RemoveDuplicateStr

func RemoveDuplicateStr(strSlice []string) []string

func RemoveItem

func RemoveItem(s []interface{}, i int) []interface{}

func RunDSL

func RunDSL(dbc *sql.DB, sql string) map[string]interface{}

func RunSQL

func RunSQL(dbc *sql.DB, sql string) map[string]interface{}

Run SELECT and return map[string]interface{}{"result": []interface{}, "error": error}

func RunSystemCommand

func RunSystemCommand(cmd string, verbose bool) string

func RunSystemCommandV2

func RunSystemCommandV2(cmd string, verbose bool) (string, error)

func SendMail

func SendMail(from string, to []string, subject string, message string, attachments []string, server, username, password string) error

func SendMailSendGrid

func SendMailSendGrid(from, to, subject, plainTextContent, htmlContent string, attachments []string) error

func Sha1Sum

func Sha1Sum(in string) string

func Sha256Sum

func Sha256Sum(in string) string

func Sha512Sum

func Sha512Sum(in string) string

func Sleep

func Sleep(duration string)

func Ternary

func Ternary(expr bool, x, y interface{}) interface{}

func Unzip

func Unzip(src, dest string) error

func Upload

func Upload(client *http.Client, url string, values map[string]io.Reader, mimetype map[string]string, headers map[string]string) (err error)

func ValidateInterfaceWithStringKeys

func ValidateInterfaceWithStringKeys(val interface{}) (interface{}, error)

Pass an interface, return same interface if they are string as key or list of string as key

func VerifyHash

func VerifyHash(password string, passwordHashString string, saltLength int) bool

func ZipDecrypt

func ZipDecrypt(filePath ...string) error

func ZipEncript

func ZipEncript(filePath ...string) string

Types

type AppConfigProperties

type AppConfigProperties map[string]string

func ReadPropertiesFile

func ReadPropertiesFile(filename string) (AppConfigProperties, error)

func ReadPropertiesString

func ReadPropertiesString(inputString string) (AppConfigProperties, error)

Jump to

Keyboard shortcuts

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