Documentation
¶
Overview ¶
Package gulu implements some common utilities.
Index ¶
- Constants
- Variables
- func CmdAttr(cmd *exec.Cmd)
- type GuluFile
- func (gl *GuluFile) Copy(source, dest string) (err error)
- func (gl *GuluFile) CopyDir(source, dest string) (err error)
- func (gl *GuluFile) CopyDirNewtimes(source, dest string) (err error)
- func (gl *GuluFile) CopyFile(source, dest string) (err error)
- func (gl *GuluFile) CopyFileNewtimes(source, dest string) (err error)
- func (gl *GuluFile) CopyNewtimes(source, dest string) (err error)
- func (*GuluFile) GetFileSize(path string) int64
- func (*GuluFile) IsBinary(content string) bool
- func (*GuluFile) IsDir(path string) bool
- func (*GuluFile) IsExist(path string) bool
- func (*GuluFile) IsHidden(path string) bool
- func (*GuluFile) IsImg(extension string) bool
- func (GuluFile) IsValidFilename(name string) bool
- func (GuluFile) RemoveEmptyDirs(dir string, excludes ...string) (err error)
- func (GuluFile) WriteFileSafer(writePath string, data []byte, perm os.FileMode) (err error)
- func (GuluFile) WriteFileSaferByHandle(handle *os.File, data []byte) (err error)
- func (GuluFile) WriteFileSaferByReader(writePath string, reader io.Reader, perm os.FileMode) (err error)
- func (GuluFile) WriteFileSaferWithoutChangeTime(writePath string, data []byte, perm os.FileMode) (err error)
- type GuluGo
- type GuluJSON
- type GuluNet
- type GuluOS
- type GuluPanic
- type GuluRand
- type GuluRet
- func (*GuluRet) NewResult() *Result
- func (*GuluRet) RetGzJSON(w http.ResponseWriter, r *http.Request, res map[string]interface{})
- func (*GuluRet) RetGzResult(w http.ResponseWriter, r *http.Request, res *Result)
- func (*GuluRet) RetJSON(w http.ResponseWriter, r *http.Request, res map[string]interface{})
- func (*GuluRet) RetResult(w http.ResponseWriter, r *http.Request, res *Result)
- type GuluRune
- type GuluStr
- func (*GuluStr) Contains(str string, strs []string) bool
- func (*GuluStr) EncloseIgnoreCase(text, open, close string, searchStrs ...string) string
- func (gs *GuluStr) Equal(slice1 []string, slice2 []string) bool
- func (gs *GuluStr) ExcludeElem(slice, excludes []string) (ret []string)
- func (*GuluStr) FromBytes(bytes []byte) string
- func (*GuluStr) HasZeroWidthCharacters(s string) bool
- func (*GuluStr) IsASCII(s string) bool
- func (*GuluStr) LCS(s1 string, s2 string) string
- func (*GuluStr) RemoveCtl(str string) string
- func (gs *GuluStr) RemoveDuplicatedElem(slice []string) (ret []string)
- func (gs *GuluStr) RemoveElem(slice []string, elem string) (ret []string)
- func (gs *GuluStr) RemoveInvisible(str string) string
- func (*GuluStr) RemoveZeroWidthCharacters(s string) string
- func (*GuluStr) RemoveZeroWidthJoiner(s string) string
- func (*GuluStr) RemoveZeroWidthNoBreakSpace(s string) string
- func (*GuluStr) RemoveZeroWidthNonJoiner(s string) string
- func (*GuluStr) RemoveZeroWidthSpace(s string) string
- func (*GuluStr) ReplaceIgnoreCase(text, searchStr, repl string) string
- func (*GuluStr) ReplacesIgnoreCase(text string, searchStrRepl ...string) string
- func (*GuluStr) SubStr(str string, length int) (ret string)
- func (*GuluStr) SubstringsBetween(str, start, end string) (ret []string)
- func (*GuluStr) ToBytes(str string) []byte
- type GuluTar
- type GuluZip
- type Logger
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Error(v ...interface{})
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Fatal(v ...interface{})
- func (l *Logger) Fatalf(format string, v ...interface{})
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) IsDebugEnabled() bool
- func (l *Logger) IsTraceEnabled() bool
- func (l *Logger) IsWarnEnabled() bool
- func (l *Logger) SetLevel(level string)
- func (l *Logger) Trace(v ...interface{})
- func (l *Logger) Tracef(format string, v ...interface{})
- func (l *Logger) Warn(v ...interface{})
- func (l *Logger) Warnf(format string, v ...interface{})
- type Result
- type ZipFile
Constants ¶
const ( Off = iota Trace Debug Info Warn Error Fatal )
Logging level.
const ( // ZWSP represents zero-width space. ZWSP = '\u200B' // ZWNBSP represents zero-width no-break space. ZWNBSP = '\uFEFF' // ZWJ represents zero-width joiner. ZWJ = '\u200D' // ZWNJ represents zero-width non-joiner. ZWNJ = '\u200C' )
Variables ¶
var ( // File utilities File GuluFile // Go utilities Go GuluGo // Net utilities Net GuluNet // OS utilities OS GuluOS // Panic utilities Panic GuluPanic // Rand utilities Rand GuluRand // Ret utilities Ret GuluRet // Rune utilities Rune GuluRune // Str utilities Str GuluStr // Zip utilities Zip GuluZip // Tar utilities Tar GuluTar // JSON utilities JSON GuluJSON )
var Log = guluLog{}
Log utilities.
Functions ¶
Types ¶
type GuluFile ¶
type GuluFile byte
GuluFile is the receiver of file utilities
func (*GuluFile) Copy ¶
Copy copies the source to the dest. Keep the dest access/mod time as the same as the source.
func (*GuluFile) CopyDir ¶
CopyDir copies the source directory to the dest directory. Keep the dest access/mod time as the same as the source.
func (*GuluFile) CopyDirNewtimes ¶
CopyDirNewtimes copies the source directory to the dest directory. Do not keep the dest access/mod time as the same as the source.
func (*GuluFile) CopyFile ¶
CopyFile copies the source file to the dest file. Keep the dest access/mod time as the same as the source.
func (*GuluFile) CopyFileNewtimes ¶
CopyFileNewtimes copies the source file to the dest file. Do not keep the dest access/mod time as the same as the source.
func (*GuluFile) CopyNewtimes ¶
CopyNewtimes copies the source to the dest. Do not keep the dest access/mod time as the same as the source.
func (*GuluFile) GetFileSize ¶
GetFileSize get the length in bytes of file of the specified path.
func (*GuluFile) IsBinary ¶
IsBinary determines whether the specified content is a binary file content.
func (*GuluFile) IsExist ¶
IsExist determines whether the file spcified by the given path is exists.
func (GuluFile) IsValidFilename ¶
func (GuluFile) RemoveEmptyDirs ¶
RemoveEmptyDirs removes all empty dirs under the specified dir path.
func (GuluFile) WriteFileSafer ¶
WriteFileSafer writes the data to a temp file and atomically move if everything else succeeds.
func (GuluFile) WriteFileSaferByHandle ¶
WriteFileSaferByHandle writes the data to a temp file and writes the original file if everything else succeeds. Note: This function does not close the file handle after writing data.
func (GuluFile) WriteFileSaferByReader ¶
func (GuluFile) WriteFileSaferByReader(writePath string, reader io.Reader, perm os.FileMode) (err error)
WriteFileSaferByReader writes the data to a temp file and atomically move if everything else succeeds.
func (GuluFile) WriteFileSaferWithoutChangeTime ¶
func (GuluFile) WriteFileSaferWithoutChangeTime(writePath string, data []byte, perm os.FileMode) (err error)
WriteFileSaferWithoutChangeTime writes the data to a temp file and atomically move if everything else succeeds, do not change the file modification time.
type GuluGo ¶
type GuluGo byte
GuluGo is the receiver of Go utilities
func (*GuluGo) GetAPIPath ¶
GetAPIPath gets the Go source code path $GOROOT/src.
func (*GuluGo) GetExecutableInGOBIN ¶
GetExecutableInGOBIN gets executable file under GOBIN path.
The specified executable should not with extension, this function will append .exe if on Windows.
func (*GuluGo) GetGoFormats ¶
GetGoFormats gets Go format tools. It may return ["gofmt", "goimports"].
type GuluJSON ¶
type GuluJSON byte
GuluJSON is the receiver of JSON utilities
func (*GuluJSON) MarshalIndentJSON ¶
func (*GuluJSON) MarshalJSON ¶
func (*GuluJSON) UnmarshalJSON ¶
type GuluNet ¶
type GuluNet byte
GuluNet is the receiver of network utilities
type GuluOS ¶
type GuluOS byte
GuluOS is the receiver of OS utilities
func (*GuluOS) Home ¶
Home returns the home directory for the executing user.
This uses an OS-specific method for discovering the home directory. An error is returned if a home directory cannot be detected.
type GuluRand ¶
type GuluRand byte
GuluRand is the receiver of random utilities
type GuluRet ¶
type GuluRet byte
GuluRet is the receiver of result utilities
func (*GuluRet) RetGzJSON ¶
RetGzJSON writes HTTP response with "Content-Type, application/json" and "Content-Encoding, gzip".
func (*GuluRet) RetGzResult ¶
RetGzResult writes HTTP response with "Content-Type, application/json" and "Content-Encoding, gzip".
type GuluRune ¶
type GuluRune byte
GuluRune is the receiver of rune utilities
func (*GuluRune) ContainChinese ¶
ContainChinese checks the specified string whether contains chinese.
func (*GuluRune) IsNumOrLetter ¶
IsNumOrLetter checks the specified rune is number or letter.
type GuluStr ¶
type GuluStr byte
GuluStr is the receiver of string utilities
func (*GuluStr) EncloseIgnoreCase ¶
Enclose encloses search strings with open and close, case-insensitively.
func (*GuluStr) ExcludeElem ¶
ExcludeElem excludes the specified elements from the slice.
func (*GuluStr) HasZeroWidthCharacters ¶
HasZeroWidthCharacters reports whether string s contains zero-width characters.
func (*GuluStr) LCS ¶
LCS gets the longest common substring of s1 and s2.
Refers to http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Longest_common_substring.
func (*GuluStr) RemoveDuplicatedElem ¶
RemoveDuplicatedElem removes the duplicated elements from the slice.
func (*GuluStr) RemoveElem ¶
RemoveElem removes the specified element from the slice.
func (*GuluStr) RemoveInvisible ¶
RemoveInvisible removes invisible characters from string str.
func (*GuluStr) RemoveZeroWidthCharacters ¶
RemoveZeroWidthCharacters removes all zero-width characters from string s.
func (*GuluStr) RemoveZeroWidthJoiner ¶
RemoveZeroWidthJoiner removes zero-width joiner characters from string s.
func (*GuluStr) RemoveZeroWidthNoBreakSpace ¶
RemoveZeroWidthNoBreakSpace removes zero-width no-break space characters from string s.
func (*GuluStr) RemoveZeroWidthNonJoiner ¶
RemoveZeroWidthNonJoiner removes zero-width non-joiner characters from string s.
func (*GuluStr) RemoveZeroWidthSpace ¶
RemoveZeroWidthSpace removes zero-width space characters from string s.
func (*GuluStr) ReplaceIgnoreCase ¶
ReplaceIgnoreCase replace searchStr with repl in the text, case-insensitively.
func (*GuluStr) ReplacesIgnoreCase ¶
ReplacesIgnoreCase replace searchStr-repl pairs in the text, case-insensitively.
func (*GuluStr) SubstringsBetween ¶
SubstringsBetween returns a slice of sub strings between the start and end.
type GuluZip ¶
type GuluZip byte
GuluZip is the receiver of zip utilities
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger represents a simple logger with level. The underlying logger is the standard Go logging "log".
func (*Logger) Fatal ¶
func (l *Logger) Fatal(v ...interface{})
Fatal prints fatal level message and exit process with code 1.
func (*Logger) IsDebugEnabled ¶
IsDebugEnabled determines whether the debug level is enabled.
func (*Logger) IsTraceEnabled ¶
IsTraceEnabled determines whether the trace level is enabled.
func (*Logger) IsWarnEnabled ¶
IsWarnEnabled determines whether the debug level is enabled.
type Result ¶
type Result struct { Code int `json:"code"` // return code Msg string `json:"msg"` // message Data interface{} `json:"data"` // data object }
Result represents a common-used result struct.
type ZipFile ¶
type ZipFile struct {
// contains filtered or unexported fields
}
ZipFile represents a zip file.
func (*ZipFile) AddDirectory ¶
AddDirectory adds a directory.
func (*ZipFile) AddDirectoryN ¶
AddDirectoryN adds directories.