Documentation ¶
Overview ¶
Common and useful utils for the Go project development.
Inclusion criteria:
- Only rely on the Go standard package
- Functions or lightweight packages
- Non-business related general tools
Index ¶
- Variables
- func AESDecrypt(cipherkey, ciphertext []byte) ([]byte, error)
- func AESEncrypt(cipherkey, src []byte) []byte
- func BytesToString(b []byte) string
- func CamelString(s string) string
- func ExtranetIP() (ip string, err error)
- func FileExists(name string) bool
- func GetCallLine(calldepth int) string
- func GetFirstGopath(allowAutomaticGuessing bool) (goPath string, err error)
- func GrepFile(patten string, filename string) (lines []string, err error)
- func IntranetIP() (string, error)
- func IsExportedName(name string) bool
- func IsExportedOrBuiltinType(t reflect.Type) bool
- func JsQueryEscape(s string) string
- func JsQueryUnescape(s string) (string, error)
- func Md5(b []byte) string
- func ObjectName(obj interface{}) string
- func PanicTrace(kb int) []byte
- func RandomBytes(n int) []byte
- func RelPath(targpath string) string
- func RemoveAllFromInt32s(set []int32, a int32) []int32
- func RemoveAllFromInt64s(set []int64, a int64) []int64
- func RemoveAllFromInterfaces(set []interface{}, a interface{}) []interface{}
- func RemoveAllFromInts(set []int, a int) []int
- func RemoveAllFromStrings(set []string, a string) []string
- func RemoveFromInt32s(set []int32, a int32) []int32
- func RemoveFromInt64s(set []int64, a int64) []int64
- func RemoveFromInterfaces(set []interface{}, a interface{}) []interface{}
- func RemoveFromInts(set []int, a int) []int
- func RemoveFromStrings(set []string, a string) []string
- func SearchFile(filename string, paths ...string) (fullpath string, err error)
- func SelfChdir()
- func SelfDir() string
- func SelfPath() string
- func SetToInt32s(set []int32, a int32) []int32
- func SetToInt64s(set []int64, a int64) []int64
- func SetToInterfaces(set []interface{}, a interface{}) []interface{}
- func SetToInts(set []int, a int) []int
- func SetToStrings(set []string, a string) []string
- func SnakeString(s string) string
- func SpaceInOne(s string) string
- func StringToBytes(s string) []byte
- func TarGz(src, dst string, includePrefix bool, logOutput func(string, ...interface{}), ...) (err error)
- func TarGzTo(src string, dstWriter io.Writer, includePrefix bool, ...) (err error)
- func URLRandomString(n int) string
- func WalkDirs(targpath string, suffixes ...string) (dirlist []string)
- func WritePidFile(pidFile ...string)
- type Map
- type Random
Constants ¶
This section is empty.
Variables ¶
var DEFAULT_PID_FILE = "log/PID"
DEFAULT_PID_FILE the default PID file name
Functions ¶
func AESDecrypt ¶
AESDecrypt decrypts a piece of data. The cipherkey argument should be the AES key, either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.
func AESEncrypt ¶
AESEncrypt encrypts a piece of data. The cipherkey argument should be the AES key, either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.
func BytesToString ¶
BytesToString convert []byte type to string type.
func CamelString ¶
CamelString converts the accepted string to a camel string (xx_yy to XxYy)
func ExtranetIP ¶
ExtranetIP get external IP addr. NOTE: Query IP information from the service API: http://pv.sohu.com/cityjson?ie=utf-8
func FileExists ¶
FileExists reports whether the named file or directory exists.
func GetFirstGopath ¶
GetFirstGopath gets the first $GOPATH value.
func GrepFile ¶
GrepFile like command grep -E for example: GrepFile(`^hello`, "hello.txt") \n is striped while read
func IsExportedName ¶
IsExportedName is this an exported - upper case - name?
func IsExportedOrBuiltinType ¶
IsExportedOrBuiltinType is this type exported or a builtin?
func JsQueryEscape ¶
JsQueryEscape escapes the string in javascript standard so it can be safely placed inside a URL query.
func JsQueryUnescape ¶
JsQueryUnescape does the inverse transformation of JsQueryEscape, converting %AB into the byte 0xAB and '+' into ' ' (space). It returns an error if any % is not followed by two hexadecimal digits.
func ObjectName ¶
func ObjectName(obj interface{}) string
ObjectName gets the type name of the object
func RandomBytes ¶
RandomBytes returns securely generated random bytes. It will panic if the system's secure random number generator fails to function correctly.
func RemoveAllFromInt32s ¶
RemoveAllFromInt32s removes all the a element from the int32 set.
func RemoveAllFromInt64s ¶
RemoveAllFromInt64s removes all the a element from the int64 set.
func RemoveAllFromInterfaces ¶
func RemoveAllFromInterfaces(set []interface{}, a interface{}) []interface{}
RemoveAllFromInterfaces removes all the a element from the interface{} set.
func RemoveAllFromInts ¶
RemoveAllFromInts removes all the a element from the int set.
func RemoveAllFromStrings ¶
RemoveAllFromStrings removes all the a element from the string set.
func RemoveFromInt32s ¶
RemoveFromInt32s removes a element from the int32 set.
func RemoveFromInt64s ¶
RemoveFromInt64s removes a element from the int64 set.
func RemoveFromInterfaces ¶
func RemoveFromInterfaces(set []interface{}, a interface{}) []interface{}
RemoveFromInterfaces removes a element from the interface{} set.
func RemoveFromInts ¶
RemoveFromInts removes a element from the int set.
func RemoveFromStrings ¶
RemoveFromStrings removes a element from the string set.
func SearchFile ¶
SearchFile Search a file in paths. this is often used in search config file in /etc ~/
func SetToInt32s ¶
SetToInt32s sets a element to the int32 set.
func SetToInt64s ¶
SetToInt64s sets a element to the int64 set.
func SetToInterfaces ¶
func SetToInterfaces(set []interface{}, a interface{}) []interface{}
SetToInterfaces sets a element to the interface{} set.
func SetToStrings ¶
SetToStrings sets a element to the string set.
func SnakeString ¶
SnakeString converts the accepted string to a snake string (XxYy to xx_yy)
func SpaceInOne ¶
SpaceInOne combines multiple consecutive space characters into one.
func StringToBytes ¶
StringToBytes convert string type to []byte type. NOTE: panic if modify the member value of the []byte.
func TarGz ¶
func TarGz(src, dst string, includePrefix bool, logOutput func(string, ...interface{}), ignoreBaseName ...string) (err error)
TarGz compresses and archives tar.gz file.
func TarGzTo ¶
func TarGzTo(src string, dstWriter io.Writer, includePrefix bool, logOutput func(string, ...interface{}), ignoreBaseName ...string) (err error)
TarGzTo compresses and archives tar.gz to dst writer.
func URLRandomString ¶
URLRandomString returns a URL-safe, base64 encoded securely generated random string. It will panic if the system's secure random number generator fails to function correctly. The length n must be an integer multiple of 4, otherwise the last character will be padded with `=`.
func WalkDirs ¶
WalkDirs traverses the directory, return to the relative path. You can specify the suffix.
func WritePidFile ¶
func WritePidFile(pidFile ...string)
WritePidFile writes the current PID to the specified file.
Types ¶
type Map ¶
type Map interface { // Load returns the value stored in the map for a key, or nil if no // value is present. // The ok result indicates whether value was found in the map. Load(key interface{}) (value interface{}, ok bool) // Store sets the value for a key. Store(key, value interface{}) // LoadOrStore returns the existing value for the key if present. // Otherwise, it stores and returns the given value. // The loaded result is true if the value was loaded, false if stored. LoadOrStore(key, value interface{}) (actual interface{}, loaded bool) // Range calls f sequentially for each key and value present in the map. // If f returns false, range stops the iteration. Range(f func(key, value interface{}) bool) // Random returns a pair kv randomly. // If exist=false, no kv data is exist. Random() (key, value interface{}, exist bool) // Delete deletes the value for a key. Delete(key interface{}) // Clear clears all current data in the map. Clear() // Len returns the length of the map. Len() int }
Map is a concurrent map with loads, stores, and deletes. It is safe for multiple goroutines to call a Map's methods concurrently.
type Random ¶
type Random struct {
// contains filtered or unexported fields
}
Random random string creater.
func (*Random) RandomString ¶
RandomString returns a base64 encoded securely generated random string. It will panic if the system's secure random number generator fails to function correctly. The length n must be an integer multiple of 4, otherwise the last character will be padded with `=`.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cron
Package cron implements a cron spec parser and job runner.
|
Package cron implements a cron spec parser and job runner. |
Package cmder exec cmd and catch the result.
|
Package cmder exec cmd and catch the result. |
errors is improved errors package.
|
errors is improved errors package. |
graceful package shutdown or reboot current process gracefully.
|
graceful package shutdown or reboot current process gracefully. |
inherit_net
Package inherit_net provides a family of Listen functions that either open a fresh connection or provide an inherited connection from when the process was started.
|
Package inherit_net provides a family of Listen functions that either open a fresh connection or provide an inherited connection from when the process was started. |