Documentation ¶
Overview ¶
Package gulu implements some common utilities.
Index ¶
- Constants
- Variables
- 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) WriteFileSafer(writePath string, data []byte, perm os.FileMode) error
- func (GuluFile) WriteFileSaferByHandle(handle *os.File, data []byte) error
- func (GuluFile) WriteFileSaferByReader(writePath string, reader io.Reader, perm os.FileMode) 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 (*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) 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 ¶
This section is empty.
Types ¶
type GuluFile ¶
type GuluFile byte
GuluFile is the receiver of file utilities
func (*GuluFile) Copy ¶ added in v1.1.8
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 ¶ added in v1.1.8
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 ¶ added in v1.1.8
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 ¶ added in v1.1.8
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) IsHidden ¶ added in v1.1.8
IsHidden checks whether the file specified by the given path is hidden.
func (GuluFile) IsValidFilename ¶ added in v1.2.2
func (GuluFile) WriteFileSafer ¶ added in v1.1.8
WriteFileSafer writes the data to a temp file and atomically move if everything else succeeds.
func (GuluFile) WriteFileSaferByHandle ¶ added in v1.1.8
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.
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 ¶ added in v1.1.8
type GuluJSON byte
GuluJSON is the receiver of JSON utilities
func (*GuluJSON) MarshalIndentJSON ¶ added in v1.1.8
func (*GuluJSON) MarshalJSON ¶ added in v1.1.8
func (*GuluJSON) UnmarshalJSON ¶ added in v1.1.8
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 ¶ added in v1.1.8
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 ¶ added in v1.1.8
Enclose encloses search strings with open and close, case-insensitively.
func (*GuluStr) HasZeroWidthCharacters ¶ added in v1.2.2
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) RemoveCtl ¶ added in v1.2.2
RemoveCtl removes all control characters from string str.
func (*GuluStr) RemoveInvisible ¶ added in v1.2.2
RemoveInvisible removes invisible characters from string str.
func (*GuluStr) RemoveZeroWidthCharacters ¶ added in v1.2.2
RemoveZeroWidthCharacters removes all zero-width characters from string s.
func (*GuluStr) RemoveZeroWidthJoiner ¶ added in v1.2.2
RemoveZeroWidthJoiner removes zero-width joiner characters from string s.
func (*GuluStr) RemoveZeroWidthNoBreakSpace ¶ added in v1.2.2
RemoveZeroWidthNoBreakSpace removes zero-width no-break space characters from string s.
func (*GuluStr) RemoveZeroWidthNonJoiner ¶ added in v1.2.2
RemoveZeroWidthNonJoiner removes zero-width non-joiner characters from string s.
func (*GuluStr) RemoveZeroWidthSpace ¶ added in v1.2.2
RemoveZeroWidthSpace removes zero-width space characters from string s.
func (*GuluStr) ReplaceIgnoreCase ¶ added in v1.1.8
ReplaceIgnoreCase replace searchStr with repl in the text, case-insensitively.
func (*GuluStr) ReplacesIgnoreCase ¶ added in v1.1.8
ReplacesIgnoreCase replace searchStr-repl pairs in the text, case-insensitively.
func (*GuluStr) SubStr ¶ added in v1.1.8
SubStr decode str into runes and get substring with the specified length.
func (*GuluStr) SubstringsBetween ¶ added in v1.2.2
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.