Documentation ¶
Overview ¶
Package helper is a set common helper functions
Index ¶
- Constants
- Variables
- func CleanPath(src string) string
- func DeepCopy(src interface{}, dst interface{}) error
- func FileToUtf8(filePath string, encodingName string) (string, error)
- func FromJson(srcJson []byte, dst interface{}) (bool, error)
- func FromJsonFile(jsonPath string, dst interface{}) (bool, error)
- func FromUnderscoreTimeStamp(src string) string
- func Gcd(src []int) int
- func Gcd2(a, b int) int
- func IsTimeStamp(src string) bool
- func IsUnderscoreTimeStamp(src string) bool
- func MakeDateTime(t time.Time) string
- func MakeTimeStamp(t time.Time) string
- func PackZip(srcPath string, dstDir string) (string, error)
- func ParseKeyValue(src string) (map[string]string, error)
- func SaveTo(outPath string, rd io.Reader) error
- func ToAlphaNumeric(src string) string
- func ToIntValue(src interface{}) (int, bool)
- func ToJsonFile(jsonPath string, src interface{}) error
- func ToJsonIndent(src interface{}) (string, error)
- func ToJsonIndentFile(jsonPath string, src interface{}) error
- func ToUnderscoreTimeStamp(src string) string
- func UnQuote(src string) string
- func UnpackZip(zipPath string, dstDir string) error
- func Utf8Reader(f *os.File, encodingName string) (io.Reader, error)
Constants ¶
const TimeStampLength = len("2012_08_17_16_04_59_123") // length of timestap string
Variables ¶
var ( Utf8bom = []byte{0xEF, 0xBB, 0xBF} Utf16LEbom = []byte{0xFF, 0xFE} Utf16BEbom = []byte{0xFE, 0xFF} Utf32LEbom = []byte{0xFF, 0xFE, 0x00, 0x00} Utf32BEbom = []byte{0x00, 0x00, 0xFE, 0xFF} )
byte order mark bytes
Functions ¶
func DeepCopy ¶
func DeepCopy(src interface{}, dst interface{}) error
DeepCopy using gob to make a deep copy from src into dst, both src and dst expected to be a pointers
func FileToUtf8 ¶
FileToUtf8 read file content and convert it to UTF-8 string.
If file starts with BOM (utf-8 utf-16LE utf-16BE utf-32LE utf-32BE) then BOM is used. If no BOM and encodingName is "" empty then file content probed to see is it already utf-8. If encodingName explicitly specified then it is used to convert file content to string. If none of above then assume default encoding: "windows-1252" on Windows and "utf-8" on Linux.
func FromJsonFile ¶
FromJsonFile reads read from json file and convert to destination pointer.
func FromUnderscoreTimeStamp ¶ added in v1.11.0
FromUnderscoreTimeStamp converts timestamp string to date-time string: 2021_07_16_13_40_53_882 into 2021-07-16 13:40:53.882 If source string is not a date-time string then return empty "" string
func IsTimeStamp ¶ added in v1.13.0
IsTimeStamp return true if src is timestamp string: 2021-07-16 13:40:53.882
func IsUnderscoreTimeStamp ¶ added in v1.11.0
IsUnderscoreTimeStamp return true if src is underscore timestamp string: 2021_07_16_13_40_53_882
func MakeDateTime ¶
MakeDateTime return date-time string, ie: 2012-08-17 16:04:59.148
func MakeTimeStamp ¶
MakeTimeStamp return timestamp string as: 2012_08_17_16_04_59_148
func PackZip ¶
PackZip create new (overwrite) zip archive from specified file or directory and all subdirs. If dstDir is "" empty then result located in source base directory.
func ParseKeyValue ¶
ParseKeyValue string of multiple key = value; pairs separated by semicolon. Key cannot be empty, value can be. Value can be escaped with "double" or 'single' quotes
func SaveTo ¶ added in v1.9.7
SaveTo copy all from source reader into new outPath file. File truncated if already exists.
func ToAlphaNumeric ¶
ToAlphaNumeric replace all non [A-Z,a-z,0-9] by _ underscore and remove repetitive underscores
func ToIntValue ¶ added in v1.9.8
ToIntValue cast src to int if it not nil and type is one of integer or float types. Return int value and true on success or 0 and false if src is nil or invalid type.
func ToJsonFile ¶
ToJsonFile convert source to json and write into jsonPath file.
func ToJsonIndent ¶
ToJsonIndent return source conveted to json indeneted string.
func ToJsonIndentFile ¶ added in v1.10.0
ToJsonIndentFile convert source to json and write into jsonPath file.
func ToUnderscoreTimeStamp ¶ added in v1.11.0
ToUnderscoreTimeStamp converts date-time string to timestamp string: 2021-07-16 13:40:53.882 into 2021_07_16_13_40_53_882 If source string is not a date-time string then return empty "" string
func UnpackZip ¶
UnpackZip unpack zip archive into specified directory, creating it if not exist. If dstDir is "" empty then result located in source base directory.
func Utf8Reader ¶
Utf8Reader return a reader to transform file content to utf-8.
If file starts with BOM (utf-8 utf-16LE utf-16BE utf-32LE utf-32BE) then BOM is used. If no BOM and encodingName is "" empty then file content probed to see is it already utf-8. If encodingName explicitly specified then it is used to convert file content to string. If none of above then assume default encoding: "windows-1252" on Windows and "utf-8" on Linux.
Types ¶
This section is empty.