utils

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: Unlicense Imports: 14 Imported by: 9

README

GIN UTILS

This dependencies for rumahlogic's developer team only.

Documentation

Index

Constants

View Source
const (
	LowerCase  kindOfCase = "lower"
	UpperCase  kindOfCase = "upper"
	Alphabet   kindOfCase = "alphabet"
	DigitCase  kindOfCase = "digit"
	SymbolCase kindOfCase = "symbol"
	AllCase    kindOfCase = "all"
	Default    kindOfCase = ""
)

Variables

View Source
var ReDupSeparatorChar = regexp.MustCompile(fmt.Sprintf("%s{2,}", SeparatorForRe))

ReDupSeparatorChar match duplicate separator string

View Source
var ReInValidChar = regexp.MustCompile(fmt.Sprintf("[^%sa-zA-Z0-9]", SeparatorForRe))

ReInValidChar match invalid slug string

View Source
var Separator = "-"

Separator separator between words

View Source
var SeparatorForRe = regexp.QuoteMeta(Separator)

SeparatorForRe for regexp

Functions

func CloseBody

func CloseBody(Body io.ReadCloser)

CloseBody for secure close io ReadCloser with message error if error

func CloseDB

func CloseDB(sql *sql.DB)

CloseDB for secure close sql DB with message error if error

func CloseFile

func CloseFile(file *os.File)

CloseFile for secure close os file with message error if error

func Convert

func Convert(source interface{}, destination interface{}) (err error)

Convert for convert from map[string]interface{} to struct or reverse or array of them

func Eq added in v1.0.1

func Eq(val1, val2, tRes, fRes interface{}) interface{}

Eq utils function

Eq means equal
Used to return the true value according to the value you want to compare.
The parameters consist of 4 data types interface{} where the first and second parameters are the values to be compared
while for the third value is the value that will be returned when the condition is true and the fourth parameter is for the value when the condition is false

Example:
exp1 := Eq("eat", "sleep", 100, 50) // exp1 = 50
exp2 := Eq("eat", "eat", 100, 50) // exp2 = 100

func EqualString

func EqualString(str, subStr string) bool

EqualString for cek if string contain substring example : EqualString("Report Service", "report") will return true.

func ErrorHandler

func ErrorHandler(err error)

ErrorHandler for print error message to console with engine name if error != nil

func GetEnvBool

func GetEnvBool(key string, val bool) bool

GetEnvBool for get env type bool

func GetEnvFloat64 added in v1.1.8

func GetEnvFloat64(key string, val float64) float64

GetEnvFloat64 for get env variables type int64 in golang

func GetEnvInt64 added in v1.1.8

func GetEnvInt64(key string, val int64) int64

GetEnvInt64 for get env variables type int64 in golang

func GetEnvString

func GetEnvString(key, defaultVal string) string

GetEnvString for get env type string

func GetEnvTimeDuration

func GetEnvTimeDuration(key string, val time.Duration) time.Duration

GetEnvTimeDuration for get env variables type time duration in golang

func Gt added in v1.0.1

func Gt(val1, val2, tRes, fRes interface{}) interface{}

Gt func for if not equals

Gt means Greater Than
Used to return the true value according to the value you want to compare.
The parameters consist of 4 data types interface{} where the first and second parameters are the values to be compared
while for the third value is the value that will be returned when the condition is true and the fourth parameter is for the value when the condition is false

Example:
exp1 := Gt(99, 100, "yes", "no") // exp1 = no
exp2 := Gt(99, 70, "yes", "no) // exp2 = yes

func Gte added in v1.0.1

func Gte(val1, val2, tRes, fRes interface{}) interface{}

Gte func for if not equals

Gte means Greater Than Equal
Used to return the true value according to the value you want to compare.
The parameters consist of 4 data types interface{} where the first and second parameters are the values to be compared
while for the third value is the value that will be returned when the condition is true and the fourth parameter is for the value when the condition is false

Example:
exp1 := Gte(99, 100, "yes", "no") // exp1 = no
exp2 := Gte(99, 70, "yes", "no) // exp2 = yes
exp3 := Gte(99, 99, "yes", "no) // exp3 = yes

func Highlight added in v1.1.7

func Highlight(str, searchText, prefix, suffix string) string

Highlight is a func for add prefix and suffix for text

func IsContainInt added in v1.0.1

func IsContainInt(str int, data []int) bool

IsContainInt Check if array string contain int

func IsContainInt64 added in v1.0.1

func IsContainInt64(str int64, data []int64) bool

IsContainInt64 Check if array string contain int64

func IsContainString

func IsContainString(str string, data []string) bool

IsContainString Check if array string contain string

func IsContainUint added in v1.0.1

func IsContainUint(str uint, data []uint) bool

IsContainUint Check if array string contain uint

func IsContainUint64 added in v1.0.1

func IsContainUint64(str uint64, data []uint64) bool

IsContainUint64 Check if array string contain uint64

func LogPrint

func LogPrint(args ...interface{})

LogPrint for print message for debug with engine name

func Lt added in v1.0.1

func Lt(val1, val2, tRes, fRes interface{}) interface{}

Lt func for if not equals

Lt means Less Than
Used to return the true value according to the value you want to compare.
The parameters consist of 4 data types interface{} where the first and second parameters are the values to be compared
while for the third value is the value that will be returned when the condition is true and the fourth parameter is for the value when the condition is false

Example:
exp1 := Lt(99, 100, "yes", "no") // exp1 = yes
exp2 := Lt(99, 70, "yes", "no) // exp2 = no

func Lte added in v1.0.1

func Lte(val1, val2, tRes, fRes interface{}) interface{}

Lte func for if not equals

Lte means Less Than Equal
Used to return the true value according to the value you want to compare.
The parameters consist of 4 data types interface{} where the first and second parameters are the values to be compared
while for the third value is the value that will be returned when the condition is true and the fourth parameter is for the value when the condition is false

Example:
exp1 := Lte(99, 100, "yes", "no") // exp1 = yes
exp2 := Lte(99, 70, "yes", "no) // exp2 = no
exp3 := Lte(99, 99, "yes", "no) // exp3 = yes

func MergeArrayInterfaces added in v1.1.5

func MergeArrayInterfaces(models ...[]interface{}) (res []interface{})

MergeArrayInterfaces This function used to merge [][]interface{} to []interface{} This function is variadic function which use two dimension array of interface{}

func Ne added in v1.0.1

func Ne(val1, val2, tRes, fRes interface{}) interface{}

Ne func for if not equals

Ne means Not Equal
Used to return the true value according to the value you want to compare.
The parameters consist of 4 data types interface{} where the first and second parameters are the values to be compared
while for the third value is the value that will be returned when the condition is true and the fourth parameter is for the value when the condition is false

Example:
exp1 := Ne("eat", "sleep", 100, 50) // exp1 = 100
exp2 := Ne("eat", "eat", 100, 50) // exp2 = 50

func PasswordValidation added in v1.1.9

func PasswordValidation(s string) (err error)

PasswordValidation for validate string must have uppercase, special char and number

func PrettyPrint

func PrettyPrint(data interface{})

PrettyPrint for print struct/map/array to console as indent view

func RandomString

func RandomString(length int, kind kindOfCase) string

RandomString is a utils for generate random string with param length of string and type of string kind = (lower/upper/digit/symbol/all) or default is lower+upper+digit

func Slugify added in v1.1.1

func Slugify(s string) string

Slugify implements make a pretty slug from the given text. e.g. Slugify("kožušček hello world") => "kozuscek-hello-world"

func SplitTime

func SplitTime(data interface{}) (hours, minutes, seconds int, err error)

func StringToUintArr

func StringToUintArr(req []string) (res []uint)

StringToUintArr for convert array of string number to unit array

func Version added in v1.1.1

func Version() string

Version return version

func WeekRange

func WeekRange(year, week int) (start, end time.Time)

WeekRange Get datetime start and end from week in year

func WeekRangeWithTime added in v1.1.6

func WeekRangeWithTime(tm time.Time) (start, end time.Time)

WeekRangeWithTime Get datetime start and end from week in year

func WeekStart

func WeekStart(year, week int) time.Time

WeekStart Get datetime start from week in year

func WeekStartWithTime added in v1.1.6

func WeekStartWithTime(tm time.Time) time.Time

WeekStartWithTime Get datetime start from week in year

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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