gulu

package module
v0.0.0-...-517be37 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2019 License: Apache-2.0 Imports: 25 Imported by: 24

Documentation

Overview

Package gulu implements some common utilities.

Index

Constants

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

Logging level.

View Source
const Version = "v1.0.0"

Version is the version of Gulu.

Variables

View Source
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
)
View Source
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) CopyDir

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

CopyDir copies the source directory to the dest directory.

func (*GuluFile) CopyFile

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

CopyFile copies the source file to the dest file.

func (*GuluFile) GetFileSize

func (*GuluFile) GetFileSize(path string) int64

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

func (*GuluFile) IsBinary

func (*GuluFile) IsBinary(content string) bool

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

func (*GuluFile) IsDir

func (*GuluFile) IsDir(path string) bool

IsDir determines whether the specified path is a directory.

func (*GuluFile) IsExist

func (*GuluFile) IsExist(path string) bool

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

func (*GuluFile) IsImg

func (*GuluFile) IsImg(extension string) bool

IsImg determines whether the specified extension is a image.

type GuluGo

type GuluGo byte

GuluGo is the receiver of Go utilities

func (*GuluGo) GetAPIPath

func (*GuluGo) GetAPIPath() string

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

func (*GuluGo) GetExecutableInGOBIN

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

func (*GuluGo) GetGoFormats() []string

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

func (*GuluGo) IsAPI

func (*GuluGo) IsAPI(path string) bool

IsAPI determines whether the specified path belongs to Go API.

type GuluNet

type GuluNet byte

GuluNet is the receiver of network utilities

func (*GuluNet) LocalIP

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

LocalIP gets the first NIC's IP address.

func (*GuluNet) LocalMac

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

LocalMac gets the first NIC's MAC address.

type GuluOS

type GuluOS byte

GuluOS is the receiver of OS utilities

func (*GuluOS) Home

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

func (*GuluOS) IsWindows() bool

IsWindows determines whether current OS is Windows.

func (*GuluOS) Pwd

func (*GuluOS) Pwd() string

Pwd gets the path of current working directory.

type GuluPanic

type GuluPanic byte

GuluPanic is the receiver of panic utilities

func (*GuluPanic) Recover

func (*GuluPanic) Recover(err *error)

Recover recovers a panic.

type GuluRand

type GuluRand byte

GuluRand is the receiver of random utilities

func (*GuluRand) Int

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

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

func (*GuluRand) Ints

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

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

func (*GuluRand) String

func (*GuluRand) String(length int) string

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

type GuluRet

type GuluRet byte

GuluRet is the receiver of result utilities

func (*GuluRet) NewResult

func (*GuluRet) NewResult() *Result

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

func (*GuluRet) RetGzJSON

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

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

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

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

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

type GuluRune

type GuluRune byte

GuluRune is the receiver of rune utilities

func (*GuluRune) IsLetter

func (*GuluRune) IsLetter(r rune) bool

IsLetter checks the specified rune is letter.

func (*GuluRune) IsNumOrLetter

func (*GuluRune) IsNumOrLetter(r rune) bool

IsNumOrLetter checks the specified rune is number or letter.

type GuluStr

type GuluStr byte

GuluStr is the receiver of string utilities

func (*GuluStr) Contains

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

Contains determines whether the str is in the strs.

func (*GuluStr) FromBytes

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

FromBytes converts the specified byte array to a string.

func (*GuluStr) LCS

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

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

Bytes converts the specified str to a byte array.

type GuluZip

type GuluZip byte

GuluZip is the receiver of zip utilities

func (*GuluZip) Create

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

Create creates a zip file with the specified filename.

func (*GuluZip) Unzip

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

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

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

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

Debug prints debug level message.

func (*Logger) Debugf

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

Debugf prints debug level message with format.

func (*Logger) Error

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

Error prints error level message.

func (*Logger) Errorf

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

Errorf prints error level message with format.

func (*Logger) Fatal

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

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

func (*Logger) Fatalf

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

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

func (*Logger) Info

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

Info prints info level message.

func (*Logger) Infof

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

Infof prints info level message with format.

func (*Logger) IsDebugEnabled

func (l *Logger) IsDebugEnabled() bool

IsDebugEnabled determines whether the debug level is enabled.

func (*Logger) IsTraceEnabled

func (l *Logger) IsTraceEnabled() bool

IsTraceEnabled determines whether the trace level is enabled.

func (*Logger) IsWarnEnabled

func (l *Logger) IsWarnEnabled() bool

IsWarnEnabled determines whether the debug level is enabled.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level string)

SetLevel sets the logging level of a logger.

func (*Logger) Trace

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

Trace prints trace level message.

func (*Logger) Tracef

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

Tracef prints trace level message with format.

func (*Logger) Warn

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

Warn prints warning level message.

func (*Logger) Warnf

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

Warnf prints warning level message with format.

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

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

AddDirectory adds a directory.

func (*ZipFile) AddDirectoryN

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

AddDirectoryN adds directories.

func (*ZipFile) AddEntry

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

AddEntry adds a entry.

func (*ZipFile) AddEntryN

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

AddEntryN adds entries.

func (*ZipFile) Close

func (z *ZipFile) Close() error

Close closes the zip file writer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL