mtool

package module
v0.0.0-...-6c5b47e Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: MIT Imports: 26 Imported by: 0

README

mtool

mateors web app necessary

How to install?

go get github.com/mateors/mtool

How to get latest update of this package?

go get -u github.com/mateors/mtool

Documentation

package mtool // import "mateors/lib/mtool"

VARIABLES

var FuncMap = template.FuncMap{
	"minus":             Mminus,
	"mFormat":           Mformat,
	"toFloat64":         MtoFloat64,
	"toString":          MtoString,
	"toWords":           AmountInWords,
	"plus":              Plus,
	"getFieldValue":     GetFieldValue,
	"sign":              GetSign,
	"fdate":             FormateDate,
	"famount":           AmountFromDebitCredit,
	"getTextMenus":      GetTextMenus,
	"getImageMenus":     GetImageMenus,
	"getMatchedRow":     GetMatchedRow,
	"getLinkRow":        GetLinkRow,
	"getLinkRowByField": GetLinkRowByField,
	"moneyFormat":       MoneyFormat,
	"detailsParser":     LinkDetailsParser,
	"subTotal":          SubTotal,
	"replaceSpace":      ReplaceSpaceBy,
	"toSlice":           StringToSlice,
	"parseDimension":    ParseDimension,
	"uPlus":             Uplus,
	"wishList":          WishList,
	"divideBy":          DivideBy,
}
FuncMap Custom function repository used in template

FUNCTIONS

  • func AmountFromDebitCredit(debit, credit interface{}) (famount string) AmountFromDebitCredit to get which one has value not 0

  • func AmountInWords(amount interface{}) (inwords string) AmountInWords any type amount to string type conversion

  • func ArrayDiff(a, b []string) []string ArrayDiff Input two string array and get the difference value array

  • func ArrayDuplicate(a, b []string) []string ArrayDuplicate Get the duplicate value array from two different array

  • func ArrayFind(array []string, value string) (bool, int) ArrayFind Find a value in_array with its index number

  • func ArrayValueExist(array []string, value string) bool ArrayValueExist Make sure a value exist in_array or not

  • func Bar(a, b, c int) Bar test func

  • func BrowserInfo(userAgent, battery string) map[string]string BrowserInfo parse useragent to map

  • func BrowserInfo2(userAgent string) map[string]string BrowserInfo2 parse useragent to map

  • func Call(m map[string]interface{}, name string, params ...interface{}) (result []reflect.Value, err error) Call advance func used in

  • func CheckError(formData url.Values, db *sql.DB) string CheckError error checklist for signup || check Multiple Condition

  • func CheckFileOrFolderExist(dirName string) bool CheckFileOrFolderExist takes one argument

  • func CheckMultipleConditionTrue(formData url.Values, funcsMap map[string]interface{}, db *mcb.DB) string CheckMultipleConditionTrue this func is used for checking multiple conditions valid or ERROR

  • func CleanText(example string) string CleanText takes any string containing any character and return Alphanumeric

  • func Convert(number int) string Convert converts number into the words representation.

  • func ConvertAnd(number int) string ConvertAnd converts number into the words representation with " and " added between number groups.

  • func DateTimeParser(inputDateTime, inputFormat, outputFormat string) (datetime string) DateTimeParser datetime parser according to your format

  • func DivideBy(a, b interface{}) float64 DivideBy to division on golang html template

  • func ErrorInSlice(slice []string, val string) (int, bool) ErrorInSlice to detect error in a string

  • func Foo() Foo test func

  • func FormateDate(date string) (fdate string) FormateDate date formatter

  • func GenerateBlockNumber() (blockNumber string) GenerateBlockNumber unique hexa code

  • func GenerateDocNumber(prefix string) (docNumber string) GenerateDocNumber to Generate random unique document number

  • func GenerateLedgerNumber(prefix, suffix string) (ledgerNumber string) GenerateLedgerNumber for accounting voucher

  • func GenerateVisitorSession() string GenerateVisitorSession using uuid

  • func GetFieldValue(tableRows []map[string]interface{}, fieldName, findMyName string) (sRow map[string]interface{}) GetFieldValue to get any field value

  • func GetImageMenus(tableRows []map[string]interface{}, menuID string) map[string]interface{} GetImageMenus for link create purpose

  • func GetLinkRow(tableRows []map[string]interface{}, imenuID string) (sRow []map[string]interface{}) GetLinkRow getMatchedRow for go template

  • func GetLinkRowByField(tableRows []map[string]interface{}, fieldName, menuID string) (sRow []map[string]interface{}) GetLinkRowByField for template page

  • func GetMatchedRow(tableRows []map[string]interface{}, fieldName, matchValue string) (sRow []map[string]interface{}) GetMatchedRow for golang html template

  • func GetSign(voucherName string) (sign string) GetSign Get a sign looking at voucher_name, used in transaction

  • func GetTextMenus(tableRows []map[string]interface{}, menuID string) map[string]interface{} GetTextMenus for text link

  • func IPAddress(RemoteAddr string) (ipaddress string) IPAddress [::1] to fresh ip

  • func LinkDetailsParser(data string) map[string]string LinkDetailsParser link string to map

  • func Mformat(a interface{}) string Mformat Custom function for template. Takes an input (Any type including int,float64,string) Return two decimal digit after the point/precision

  • func Mminus(a, b interface{}) float64 Mminus Custom function for template, Takes two input and return result after subtraction

  • func MoneyFormat(amount interface{}) string MoneyFormat format any number to money format, comma separated

  • func MtoFloat64(a interface{}) float64 MtoFloat64 Custom function for template. Takes an input (Any type including int,float64,string) Convert it to float64 and return

  • func MtoString(a interface{}) string MtoString Custom function for template, Takes one input of any formate and convert it to string

  • func ParseDimension(text, separator string) map[string]string ParseDimension for samsung/FDL company mobile handset only

  • func Plus(a, b interface{}) float64 Plus to Add two input in golang html template

  • func ReadUserIP(r *http.Request) string ReadUserIP read ip from http pointer to request

  • func RegExFindMatch(pattern, data string) (match []string) RegExFindMatch find pattern in data string

  • func RemoveFromSlice(s []string, i int) []string RemoveFromSlice Remove an item from a slice

  • func RemoveFromSliceByValue(s []string, value string) []string RemoveFromSliceByValue Remove an item from a slice

  • func ReplaceSpaceBy(productName, replaceby string) (formattedName string) ReplaceSpaceBy remove space by any given char

  • func RequestURLtoPage(requestURI string) (pageName, query string) RequestURLtoPage r.RequestURI to path and query string

  • func ReturnIndexByValue(s []string, val string) (index int) ReturnIndexByValue to Get index number by its value from a slice

  • func SQLNullString(s interface{}) sql.NullString SQLNullString for sql null char

  • func StartEndDate(dateTime, layout string) (startDate, endDate string) StartEndDate takes two argument, both are string, dateTime="", layout := "2006-01-02 03:04:05"

  • func StringToSlice(text, separator string) (slice []string) StringToSlice create a slice using separator

  • func SubTotal(data []map[string]interface{}) float64 SubTotal calculate total of a map

  • func Sum(nums ...float64) (total float64) Sum input as many number as wish, get all number summation ex: 10.50,20.03,50.25 or slice ending with three dots[slice...]-> tool.Sum(aSlice...)

  • func TimeStampToDate(timeStamp string) (dateFormated string) TimeStampToDate formatted date

  • func Uplus(nums ...interface{}) string Uplus to add multiple values

  • func WishList(productID string, wisthList []map[string]interface{}) bool WishList check if product_id exist in whishlist

  • func DayCountBetweenTwoDates(startDate, endDate) int count number of days between two given date

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FuncMap = template.FuncMap{
	"minus":             Mminus,
	"mFormat":           Mformat,
	"toFloat64":         MtoFloat64,
	"toString":          MtoString,
	"toWords":           AmountInWords,
	"plus":              Plus,
	"getFieldValue":     GetFieldValue,
	"sign":              GetSign,
	"fdate":             FormateDate,
	"famount":           AmountFromDebitCredit,
	"getTextMenus":      GetTextMenus,
	"getImageMenus":     GetImageMenus,
	"getMatchedRow":     GetMatchedRow,
	"getLinkRow":        GetLinkRow,
	"getLinkRowByField": GetLinkRowByField,
	"moneyFormat":       MoneyFormat,
	"detailsParser":     LinkDetailsParser,
	"subTotal":          SubTotal,
	"replaceSpace":      ReplaceSpaceBy,
	"toSlice":           StringToSlice,
	"parseDimension":    ParseDimension,
	"uPlus":             Uplus,
	"wishList":          WishList,
	"divideBy":          DivideBy,
}

FuncMap Custom function repository used in template

Functions

func AmountFromDebitCredit

func AmountFromDebitCredit(debit, credit interface{}) (famount string)

AmountFromDebitCredit to get which one has value not 0

func AmountInWords

func AmountInWords(amount interface{}) (inwords string)

AmountInWords any type amount to string type conversion

func ArrayDiff

func ArrayDiff(a, b []string) []string

ArrayDiff Input two string array and get the difference value array

func ArrayDuplicate

func ArrayDuplicate(a, b []string) []string

ArrayDuplicate Get the duplicate value array from two different array

func ArrayFind

func ArrayFind(array []string, value string) (bool, int)

ArrayFind Find a value in_array with its index number

func ArrayValueExist

func ArrayValueExist(array []string, value string) bool

ArrayValueExist Make sure a value exist in_array or not

func BrowserInfo

func BrowserInfo(userAgent, battery string) map[string]string

BrowserInfo parse useragent to map

func BrowserInfo2

func BrowserInfo2(userAgent string) map[string]string

BrowserInfo2 parse useragent to map

func Call

func Call(m map[string]interface{}, name string, params ...interface{}) (result []reflect.Value, err error)

Call advance func used in

func CheckFileOrFolderExist

func CheckFileOrFolderExist(dirName string) bool

CheckFileOrFolderExist takes one argument

func CleanText

func CleanText(example string) string

CleanText takes any string containing any character and return Alphanumeric

func Convert

func Convert(number int) string

Convert converts number into the words representation.

func ConvertAnd

func ConvertAnd(number int) string

ConvertAnd converts number into the words representation with " and " added between number groups.

func DateInBetween

func DateInBetween(dateFormat, compareDate, startDate, endDate string) bool

func DateTimeParser

func DateTimeParser(inputDateTime, inputFormat, outputFormat string) (datetime string)

DateTimeParser datetime parser according to your format

func DayCountBetweenTwoDates

func DayCountBetweenTwoDates(startDate, endDate string) int

func DecodeStr

func DecodeStr(hexcode, password string) (plaintext string)

DecodeStr ...

func DivideBy

func DivideBy(a, b interface{}) float64

DivideBy to division on golang html template

func EncodeStr

func EncodeStr(text, password string) (hexcode string)

EncodeStr ------------

func ErrorInSlice

func ErrorInSlice(slice []string, val string) (int, bool)

ErrorInSlice to detect error in a string

func FormateDate

func FormateDate(date string) (fdate string)

FormateDate date formatter

func GenerateBlockNumber

func GenerateBlockNumber() (blockNumber string)

GenerateBlockNumber unique hexa code

func GenerateDocNumber

func GenerateDocNumber(prefix string) (docNumber string)

GenerateDocNumber to Generate random unique document number

func GenerateLedgerNumber

func GenerateLedgerNumber(prefix, suffix string) (ledgerNumber string)

GenerateLedgerNumber for accounting voucher

func GenerateVisitorSession

func GenerateVisitorSession() string

GenerateVisitorSession using uuid

func GetFieldValue

func GetFieldValue(tableRows []map[string]interface{}, fieldName, findMyName string) (sRow map[string]interface{})

GetFieldValue to get any field value

func GetImageMenus

func GetImageMenus(tableRows []map[string]interface{}, menuID string) map[string]interface{}

GetImageMenus for link create purpose

func GetLinkRow

func GetLinkRow(tableRows []map[string]interface{}, imenuID string) (sRow []map[string]interface{})

GetLinkRow getMatchedRow for go template

func GetLinkRowByField

func GetLinkRowByField(tableRows []map[string]interface{}, fieldName, menuID string) (sRow []map[string]interface{})

GetLinkRowByField for template page

func GetMapValue

func GetMapValue(mapData map[string]string, key string) (val string)

GetMapValue safer way to get value from map

func GetMapValueI

func GetMapValueI(mapData map[string]interface{}, key string) (val string)

GetMapValueI safer way to get value from map

func GetMatchedRow

func GetMatchedRow(tableRows []map[string]interface{}, fieldName, matchValue string) (sRow []map[string]interface{})

GetMatchedRow for golang html template

func GetSign

func GetSign(voucherName string) (sign string)

GetSign Get a sign looking at voucher_name, used in transaction

func GetStructName

func GetStructName(myvar interface{}) string

GetStructName get struct to its name

func GetTextMenus

func GetTextMenus(tableRows []map[string]interface{}, menuID string) map[string]interface{}

GetTextMenus for text link

func GetVarType

func GetVarType(myvar interface{}) string

GetVarType any variable to its underlysing data type

func HashBcrypt

func HashBcrypt(password string) (hash string)

HashBcrypt Generate string to hash

func HashCompare

func HashCompare(password, hashpassword string) bool

HashCompare compare plaintext password with hash text

func IPAddress

func IPAddress(RemoteAddr string) (ipaddress string)

IPAddress [::1] to fresh ip

func LinkDetailsParser

func LinkDetailsParser(data string) map[string]string

LinkDetailsParser link string to map

func MapToCleanFieldSlice

func MapToCleanFieldSlice(sfMap map[string]string) []string

MapToCleanFieldSlice ...

func MapToString

func MapToString(sRow map[string]string) string

MapToString map to string comma separated input=map[access_name:student cid:1 login_id:2] output=access_name:student,cid:1,login_id:2

func Mformat

func Mformat(a interface{}) string

Mformat Custom function for template. Takes an input (Any type including int,float64,string) Return two decimal digit after the point/precision

func Mminus

func Mminus(a, b interface{}) float64

Mminus Custom function for template, Takes two input and return result after subtraction

func MoneyFormat

func MoneyFormat(amount interface{}) string

MoneyFormat format any number to money format, comma separated

func MtoFloat64

func MtoFloat64(a interface{}) float64

MtoFloat64 Custom function for template. Takes an input (Any type including int,float64,string) Convert it to float64 and return

func MtoString

func MtoString(a interface{}) string

MtoString Custom function for template, Takes one input of any formate and convert it to string

func PaddingLeft

func PaddingLeft(seed interface{}, padStr string, length int) (retStr string)

PaddingLeft ..

func PaddingRight

func PaddingRight(seed interface{}, padStr string, length int) (retStr string)

PaddingRight ...

func ParseDimension

func ParseDimension(text, separator string) map[string]string

ParseDimension for samsung/FDL company mobile handset only

func Plus

func Plus(a, b interface{}) float64

Plus to Add two input in golang html template

func ReadUserIP

func ReadUserIP(r *http.Request) string

ReadUserIP read ip from http pointer to request

func RegExFindMatch

func RegExFindMatch(pattern, data string) (match []string)

RegExFindMatch find pattern in data string

func RemoveFromSlice

func RemoveFromSlice(s []string, i int) []string

RemoveFromSlice Remove an item from a slice

func RemoveFromSliceByValue

func RemoveFromSliceByValue(s []string, value string) []string

RemoveFromSliceByValue Remove an item from a slice

func ReplaceSpaceBy

func ReplaceSpaceBy(productName, replaceby string) (formattedName string)

ReplaceSpaceBy remove space by any given char

func RequestURLtoPage

func RequestURLtoPage(requestURI string) (pageName, query string)

RequestURLtoPage r.RequestURI to path and query string

func ReturnIndexByValue

func ReturnIndexByValue(s []string, val string) (index int)

ReturnIndexByValue to Get index number by its value from a slice

func SQLNullString

func SQLNullString(s interface{}) sql.NullString

SQLNullString for sql null char

func SliceValueExist

func SliceValueExist[T comparable](s []T, v T) bool

Generics implementation, golang version 1.18 required

func StartEndDate

func StartEndDate(dateTime, layout string) (startDate, endDate string)

StartEndDate takes two argument, both are string, dateTime="", layout := "2006-01-02 03:04:05"

func StringInSlice

func StringInSlice(slice []string, val string) (int, bool)

func StringToMap

func StringToMap(output string) map[string]string

StringToMap comma separated string to map input=access_name:student,cid:1,login_id:2 output=map[access_name:student cid:1 login_id:2]

func StringToSlice

func StringToSlice(text, separator string) (slice []string)

StringToSlice create a slice using separator

func StructToFields

func StructToFields(structRef interface{}) []string

StructToFields structToFields

func StructToFieldsType

func StructToFieldsType(structRef interface{}) map[string]string

StructToFieldsType get struct to its field_name and data type

func SubTotal

func SubTotal(data []map[string]interface{}) float64

SubTotal calculate total of a map

func Sum

func Sum(nums ...float64) (total float64)

Sum input as many number as wish, get all number summation ex: 10.50,20.03,50.25 or slice ending with three dots[slice...]-> tool.Sum(aSlice...)

func TimeNow

func TimeNow() string

TimeNow current system time mysql datetime format 2006-01-02 15:04:05 = 4digitYear-2digitMonth-2digitDate 24HourFormatHour:minute:second

func TimeNowFormatted

func TimeNowFormatted(timeFormat string) string

TimeNowFormatted "2006-01-02 15:04:05" Any format you wish as an output

func TimeStampToDate

func TimeStampToDate(timeStamp string) (dateFormated string)

TimeStampToDate formatted date

func ToString

func ToString(data interface{}) string

ToString take one argument of any dataType and convert into string

func ToTitle

func ToTitle(str string) string

func Uplus

func Uplus(nums ...interface{}) string

Uplus to add multiple values

func ValueType

func ValueType(v interface{}) string

ValueType ...

func WishList

func WishList(productID string, wisthList []map[string]interface{}) bool

WishList check if product_id exist in whishlist

Types

This section is empty.

Jump to

Keyboard shortcuts

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