Documentation ¶
Overview ¶
Package util provides helper methods for development. This package is for offline processing and not used in frontend code.
Index ¶
- func BypassReader(label string, input io.Reader) (io.Reader, error)
- func CheckDownload(url, filePath string, overwrite bool) (err error)
- func CreateDirIfNotExist(filepath string)
- func DecodeUtf16XML(r io.Reader, v interface{}) (err error)
- func Download(url, filePath string) (err error)
- func IsRunOnGitHubActions() bool
- func IsRunOnGitLabCI() bool
- func IsRunOnTravisCI() bool
- func LoadJsonConfig(fp string) (conf map[string]string, err error)
- func LocalPrintln(a ...interface{})
- func PrettyPrint(v interface{}) (err error)
- func ReadlinesFromFile(filePath string) (lines []string, err error)
- func S2T(s string) string
- func SaveJsonFile(v interface{}, path string)
- func T2S(s string) string
- func TwPoToCN(twPOPath, cnPOPath string)
- func Zg2uni(str string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BypassReader ¶
BypassReader is a workaround to process UTF-16 XML. See
https://groups.google.com/forum/#!topic/golang-nuts/tXcECEKC2rs https://stackoverflow.com/a/50812725
for more information.
func CheckDownload ¶
CheckDownload is the same as Download, except the third argument specifies whether to overwrite local file if it already exists.
func CreateDirIfNotExist ¶
func CreateDirIfNotExist(filepath string)
CreateDirIfNotExist creates the directory containing the file if the directory does not exist, given the path of the file. Similar to the shell command “mkdir -p“. This method does not return error. If the directory cannot be made, this method panics.
func DecodeUtf16XML ¶
DecodeUtf16XML decodes UTF-16 encoded XML. The first argument could be an UTF-16 encoded XML file opened by os.Open method. The seconde argument is the struct used to decode the XML.
func Download ¶
Download downloads the url to local path specified by the second argument. If the local file already exists, it will be overwritten.
func IsRunOnGitHubActions ¶
func IsRunOnGitHubActions() bool
IsRunOnGitHubActions checks if running on GitHub Actions environment.
func IsRunOnGitLabCI ¶
func IsRunOnGitLabCI() bool
IsRunOnGitLabCI checks if running on GitLab CI/CD environment.
func IsRunOnTravisCI ¶
func IsRunOnTravisCI() bool
IsRunOnTravisCI checks if running on TRAVIS CI environment.
func LoadJsonConfig ¶
LoadJsonConfig loads map[string]string data from the json file. Make sure the given JSON file is of the struct map[string]string.
func LocalPrintln ¶
func LocalPrintln(a ...interface{})
LocalPrintln will not print on Travis CI or GitLab CI/CD environment.
func PrettyPrint ¶
func PrettyPrint(v interface{}) (err error)
PrettyPrint pretty-prints Go variable (struct, map, array, slice, etc.).
func ReadlinesFromFile ¶
ReadlinesFromFile reads lines from the file.
func SaveJsonFile ¶
func SaveJsonFile(v interface{}, path string)
SaveJsonFile saves the data to JSON file.
Types ¶
This section is empty.