Documentation ¶
Index ¶
- Constants
- Variables
- func AesDecrypt(cipherText string, secretKey string) (string, error)
- func AesEncrypt(plainText string, secretKey string) (string, error)
- func Base64Encode(s string) string
- func Base64ToImg(tmp string, src string) (*os.File, error)
- func ComputeHmac256(message string, secret string) string
- func FormatToIdrCurrency(n int) string
- func GetJakartaNowTime() time.Time
- func GetJsonDataFromUrl(url string, target interface{}) error
- func GetXmlDataFromUrl(url string, target interface{}) error
- func InArray(val interface{}, array interface{}) (exists bool, index int)
- func InArrayContains(val string, checkArray []string) bool
- func InArrayNoIndex(val interface{}, array interface{}) bool
- func IsEmpty(object interface{}) bool
- func IsValidUrl(uri string) bool
- func IsatPrefix(hp string) bool
- func Md5Encrypt(text string) string
- func SaveFileToDisk(file multipart.File, saveLoc string) error
- func Sha1Encrypt(s string) string
- func Sha1_HMAC(k string, message string) string
- func Sha256Encrypt(s string) string
- func Sha256_HMAC(k string, message string) string
- func Sha512Encrypt(s string) string
- func StringIsJSON(s string) bool
- func StringRandom(length int) string
- func StringRandomWithCharset(length int, charset string) string
- func ThreePrefix(hp string) bool
- func TselPrefix(hp string) bool
- func WhiteSpaceRemove(str string) string
- func XlPrefix(hp string) bool
Constants ¶
const ( ONE_KILO = 1000 ONE_KILOBYTE = 1024 ONE_MILLION = 1000000 ONE_MEGABYTE = 1048576 OUNCE_TO_GRAM = 32.148 )
const ( STRING_NUMBER = "0123456789" STRING_ALPHABET_LOWER = "abcdefghijklmnopqrstuvwxyz" STRING_ALPHABET_UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" STRING_ALPHANUMERIC = STRING_ALPHABET_LOWER + STRING_ALPHABET_UPPER + STRING_NUMBER )
const ( MYSQL_DATE_FORMAT = "2006-01-02" MYSQL_TIME_FORMAT = "15:04:05" MYSQL_DATETIME_FORMAT = MYSQL_DATE_FORMAT + " " + MYSQL_TIME_FORMAT ISO8601_TIME_FORMAT = "2006-01-02T15:04:03.000-0700" )
Variables ¶
var JakartaTime = time.FixedZone("Asia/Jakarta", 7*60*60)
JakartaTime is default location of application with timezone = Asia/Jakarta (UTC+7)
Functions ¶
func Base64Encode ¶
func Base64ToImg ¶
Convert base64 of image to standard img file Currently only support jpeg and png
func ComputeHmac256 ¶
func FormatToIdrCurrency ¶
Function to convert int to IDR currency format Ex: FormatToIdrCurrency(100000) // return "100.000"
func GetJakartaNowTime ¶
func GetJsonDataFromUrl ¶
Helper to extract json data from given URL, should be using GET method var str SomeStruct Ex: GetJson("https://someurl.com", &str)
func GetXmlDataFromUrl ¶
Helper to extract XML data from given URL, should be using GET method var str SomeStruct Ex: GetXml("https://someurl.com", &str)
func InArray ¶
Ex: var a int var b []int
a = 1 b = []int{1, 2, 3}
InArray(a, b) // return true, 0
Could be used to check other type as well, such as string, uint, other basic types
func InArrayContains ¶
Same like InArray function but only for string, faster than InArray
func InArrayNoIndex ¶
func InArrayNoIndex(val interface{}, array interface{}) bool
Same like InArray function but not returning index Could be used to check other type as well, such as string, uint, other basic types
func IsValidUrl ¶
isValidUrl tests a string to determine if it is a well-structured url or not. https://golangcode.com/how-to-check-if-a-string-is-a-url/ Ex: IsValidUrl("https://someurl.com")
func IsatPrefix ¶
func Md5Encrypt ¶
func SaveFileToDisk ¶
Function to save multipart file into desired location Ex: SaveFileToDisk(file, "/tmp/temporary_file")
func Sha1Encrypt ¶
func Sha256Encrypt ¶
func Sha256_HMAC ¶
func Sha512Encrypt ¶
func StringIsJSON ¶
Function to check whether string can be converted to json or not
func StringRandom ¶
Randomize string with lowercase alphabet, uppercase alphabet, number with given length Ex: StringRandom(5) // return "ab12F"
func StringRandomWithCharset ¶
Randomize string with given length and charset Ex: StringRandomWithCharset(5, "abcde") // return "aabad"
func ThreePrefix ¶
func TselPrefix ¶
func WhiteSpaceRemove ¶
Remove whitespace from string Ex: WhiteSpaceRemove(" lorem ipsum ") // return "loremipsum"
Types ¶
This section is empty.