gulu: github.com/b3log/gulu Index | Files

package gulu

import "github.com/b3log/gulu"

Package gulu implements some common utilities.

Index

Package Files

file.go go.go gulu.go log.go net.go os.go panic.go rand.go ret.go rune.go string.go zip.go

Constants

const (
    Off = iota
    Trace
    Debug
    Info
    Warn
    Error
    Fatal
)

Logging level.

const Version = "v1.0.0"

Version is the version of Gulu.

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
)
var Log = guluLog{}

Log utilities.

type GuluFile Uses

type GuluFile byte

GuluFile is the receiver of file utilities

func (*GuluFile) CopyDir Uses

func (*GuluFile) CopyDir(source string, dest string) (err error)

CopyDir copies the source directory to the dest directory.

func (*GuluFile) CopyFile Uses

func (*GuluFile) CopyFile(source string, dest string) (err error)

CopyFile copies the source file to the dest file.

func (*GuluFile) GetFileSize Uses

func (*GuluFile) GetFileSize(path string) int64

GetFileSize get the length in bytes of file of the specified path.

func (*GuluFile) IsBinary Uses

func (*GuluFile) IsBinary(content string) bool

IsBinary determines whether the specified content is a binary file content.

func (*GuluFile) IsDir Uses

func (*GuluFile) IsDir(path string) bool

IsDir determines whether the specified path is a directory.

func (*GuluFile) IsExist Uses

func (*GuluFile) IsExist(path string) bool

IsExist determines whether the file spcified by the given path is exists.

func (*GuluFile) IsImg Uses

func (*GuluFile) IsImg(extension string) bool

IsImg determines whether the specified extension is a image.

type GuluGo Uses

type GuluGo byte

GuluGo is the receiver of Go utilities

func (*GuluGo) GetAPIPath Uses

func (*GuluGo) GetAPIPath() string

GetAPIPath gets the Go source code path $GOROOT/src.

func (*GuluGo) GetExecutableInGOBIN Uses

func (*GuluGo) GetExecutableInGOBIN(executable string) string

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 Uses

func (*GuluGo) GetGoFormats() []string

GetGoFormats gets Go format tools. It may return ["gofmt", "goimports"].

func (*GuluGo) IsAPI Uses

func (*GuluGo) IsAPI(path string) bool

IsAPI determines whether the specified path belongs to Go API.

type GuluNet Uses

type GuluNet byte

GuluNet is the receiver of network utilities

func (*GuluNet) LocalIP Uses

func (*GuluNet) LocalIP() (string, error)

LocalIP gets the first NIC's IP address.

func (*GuluNet) LocalMac Uses

func (*GuluNet) LocalMac() (string, error)

LocalMac gets the first NIC's MAC address.

type GuluOS Uses

type GuluOS byte

GuluOS is the receiver of OS utilities

func (*GuluOS) Home Uses

func (*GuluOS) Home() (string, error)

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.

func (*GuluOS) IsWindows Uses

func (*GuluOS) IsWindows() bool

IsWindows determines whether current OS is Windows.

func (*GuluOS) Pwd Uses

func (*GuluOS) Pwd() string

Pwd gets the path of current working directory.

type GuluPanic Uses

type GuluPanic byte

GuluPanic is the receiver of panic utilities

func (*GuluPanic) Recover Uses

func (*GuluPanic) Recover(err *error)

Recover recovers a panic.

type GuluRand Uses

type GuluRand byte

GuluRand is the receiver of random utilities

func (*GuluRand) Int Uses

func (*GuluRand) Int(min int, max int) int

Int returns a random integer in range [min, max].

func (*GuluRand) Ints Uses

func (*GuluRand) Ints(from, to, size int) []int

Ints returns a random integer array with the specified from, to and size.

func (*GuluRand) String Uses

func (*GuluRand) String(length int) string

String returns a random string ['a', 'z'] in the specified length

type GuluRet Uses

type GuluRet byte

GuluRet is the receiver of result utilities

func (*GuluRet) NewResult Uses

func (*GuluRet) NewResult() *Result

NewResult creates a result with Code=0, Msg="", Data=nil.

func (*GuluRet) RetGzJSON Uses

func (*GuluRet) RetGzJSON(w http.ResponseWriter, r *http.Request, res map[string]interface{})

RetGzJSON writes HTTP response with "Content-Type, application/json" and "Content-Encoding, gzip".

func (*GuluRet) RetGzResult Uses

func (*GuluRet) RetGzResult(w http.ResponseWriter, r *http.Request, res *Result)

RetGzResult writes HTTP response with "Content-Type, application/json" and "Content-Encoding, gzip".

func (*GuluRet) RetJSON Uses

func (*GuluRet) RetJSON(w http.ResponseWriter, r *http.Request, res map[string]interface{})

RetJSON writes HTTP response with "Content-Type, application/json".

func (*GuluRet) RetResult Uses

func (*GuluRet) RetResult(w http.ResponseWriter, r *http.Request, res *Result)

RetResult writes HTTP response with "Content-Type, application/json".

type GuluRune Uses

type GuluRune byte

GuluRune is the receiver of rune utilities

func (*GuluRune) IsLetter Uses

func (*GuluRune) IsLetter(r rune) bool

IsLetter checks the specified rune is letter.

func (*GuluRune) IsNumOrLetter Uses

func (*GuluRune) IsNumOrLetter(r rune) bool

IsNumOrLetter checks the specified rune is number or letter.

type GuluStr Uses

type GuluStr byte

GuluStr is the receiver of string utilities

func (*GuluStr) Contains Uses

func (*GuluStr) Contains(str string, strs []string) bool

Contains determines whether the str is in the strs.

func (*GuluStr) FromBytes Uses

func (*GuluStr) FromBytes(bytes []byte) string

FromBytes converts the specified byte array to a string.

func (*GuluStr) LCS Uses

func (*GuluStr) LCS(s1 string, s2 string) string

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) ToBytes Uses

func (*GuluStr) ToBytes(str string) []byte

Bytes converts the specified str to a byte array.

type GuluZip Uses

type GuluZip byte

GuluZip is the receiver of zip utilities

func (*GuluZip) Create Uses

func (*GuluZip) Create(filename string) (*ZipFile, error)

Create creates a zip file with the specified filename.

func (*GuluZip) Unzip Uses

func (*GuluZip) Unzip(zipFilePath, destination string) error

Unzip extracts a zip file specified by the zipFilePath to the destination.

type Logger Uses

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) Debug Uses

func (l *Logger) Debug(v ...interface{})

Debug prints debug level message.

func (*Logger) Debugf Uses

func (l *Logger) Debugf(format string, v ...interface{})

Debugf prints debug level message with format.

func (*Logger) Error Uses

func (l *Logger) Error(v ...interface{})

Error prints error level message.

func (*Logger) Errorf Uses

func (l *Logger) Errorf(format string, v ...interface{})

Errorf prints error level message with format.

func (*Logger) Fatal Uses

func (l *Logger) Fatal(v ...interface{})

Fatal prints fatal level message and exit process with code 1.

func (*Logger) Fatalf Uses

func (l *Logger) Fatalf(format string, v ...interface{})

Fatalf prints fatal level message with format and exit process with code 1.

func (*Logger) Info Uses

func (l *Logger) Info(v ...interface{})

Info prints info level message.

func (*Logger) Infof Uses

func (l *Logger) Infof(format string, v ...interface{})

Infof prints info level message with format.

func (*Logger) IsDebugEnabled Uses

func (l *Logger) IsDebugEnabled() bool

IsDebugEnabled determines whether the debug level is enabled.

func (*Logger) IsTraceEnabled Uses

func (l *Logger) IsTraceEnabled() bool

IsTraceEnabled determines whether the trace level is enabled.

func (*Logger) IsWarnEnabled Uses

func (l *Logger) IsWarnEnabled() bool

IsWarnEnabled determines whether the debug level is enabled.

func (*Logger) SetLevel Uses

func (l *Logger) SetLevel(level string)

SetLevel sets the logging level of a logger.

func (*Logger) Trace Uses

func (l *Logger) Trace(v ...interface{})

Trace prints trace level message.

func (*Logger) Tracef Uses

func (l *Logger) Tracef(format string, v ...interface{})

Tracef prints trace level message with format.

func (*Logger) Warn Uses

func (l *Logger) Warn(v ...interface{})

Warn prints warning level message.

func (*Logger) Warnf Uses

func (l *Logger) Warnf(format string, v ...interface{})

Warnf prints warning level message with format.

type Result Uses

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 Uses

type ZipFile struct {
    // contains filtered or unexported fields
}

ZipFile represents a zip file.

func (*ZipFile) AddDirectory Uses

func (z *ZipFile) AddDirectory(path, dirName string) error

AddDirectory adds a directory.

func (*ZipFile) AddDirectoryN Uses

func (z *ZipFile) AddDirectoryN(path string, names ...string) error

AddDirectoryN adds directories.

func (*ZipFile) AddEntry Uses

func (z *ZipFile) AddEntry(path, name string) error

AddEntry adds a entry.

func (*ZipFile) AddEntryN Uses

func (z *ZipFile) AddEntryN(path string, names ...string) error

AddEntryN adds entries.

func (*ZipFile) Close Uses

func (z *ZipFile) Close() error

Close closes the zip file writer.

Package gulu imports 25 packages (graph) and is imported by 21 packages. Updated 2019-10-09. Refresh now. Tools for package owners.