package
1.0.0
Repository: https://github.com/cloud01-wu/cgsl.git
Documentation: pkg.go.dev

# README

util

Dependency

uuid used in RandomUUIDString

Table of contexts


Documentation

AES

AesEncryptCBC

Description

Using this function to encrypt byte by AES algorithm using CBC mode

func AesEncryptCBC(origData []byte, key []byte) (encrypted []byte)
ParameterDescription
origDataByte data which want to encrypt
keykey of encrypt algorithm(key must be 16, 24 or 32 bytes)
ResponseDescription
encryptedbyte data after encrypted
errgo error(nil when success)

Usage

encryptByte, err := util.AesEncryptCBC([]byte("test"), []byte("1234567890123456"))

AesDecryptCBC

Description

Using this function to decrypt byte which encrypt by AES algorithm using CBC mode

func AesDecryptCBC(encrypted []byte, key []byte) (decrypted []byte)
ParameterDescription
encryptedbyte which encrypt by AES algorithm using CBC mode
keykey which used when encrypt
ResponseDescription
decryptedbyte data after decrypted
errgo error(nil when success)

Usage

// to get encryptByte
encryptByte, _ := util.AesEncryptCBC([]byte("test"), []byte("1234567890123456")) 
// decryptByte should be "test"
decryptByte, err := util.AesDecryptCBC(encryptByte, []byte("1234567890123456"))

AlgorithmUtil

RandString

Description

Use this function to get random string of given length

func RandString(n int) string
ParameterDescription
nlength of random string which want to get
ResponseDescription
stringrandom string of given length

Usage

length := 8
randomString := util.RandString(length)

RandomUUIDString

Description

Use this function to generate a random UUID-V4 string

func RandomUUIDString() string
ResponseDescription
stringrandom UUID-V4 string

Usage

uuidString := util.RandomUUIDString()

NewURN

Description

Use this function to generate a urn string

func NewURN(service string, resource string, tenant string, name string) string
ParameterDescription
servicename of service
resource namename of resource
account UUIDUUID of account
object UUIDname of resource

NOTICE: The specific tenant with name parameters should be unique of entire system

ResponseDescription
stringurn string

Usage

urnString := util.NewURN(
    "mss",
    "video",
    "9089f025-d49f-46a2-a62e-329febaffcfc",
    "56971a12-7200-4076-a97c-c88e2fa4d745"))

ParseURN

Description

Parse urn string to urn object

type Urn struct {
	Service  string
	Resource string
    Account  string
	Object   string
}

func ParseURN(urn string) (Urn, error)
ParameterDescription
urnurn string
ResponseDescription
urnurn object
errgo error(nil when success)

Usage

urnString := util.NewURN("jms", "user", "1c07a064-d4c1-4e53-a137-f1fb2a515ab2"))
urnObject := util.ParseURN(urnString)

ArgumentUtil

GetAsByte

Description

Use this function to get arguement in slice of interface with assertion type(byte)

func GetAsByte(arguments []interface{}, idx int, defaultValue int8) int8
ParameterDescription
argumentsslice of interface{}
idxindex of target element
defaultValuereturn value if error
ResponseDescription
valuevalue of assertion type

Usage

testSlice := []interface{}{int8(0), "1"} // example
getByte := util.GetAsByte(testSlice, 0, int8(1))

GetAsShort

Description

Use this function to get arguement in slice of interface with assertion type(short)

func GetAsShort(arguments []interface{}, idx int, defaultValue int16) int16
ParameterDescription
argumentsslice of interface{}
idxindex of target element
defaultValuereturn value if error
ResponseDescription
valuevalue of assertion type

Usage

testSlice := []interface{}{int16(0), "1"} // example
getShort := util.GetAsShort(testSlice, 0, int16(1))

GetAsInt

Description

Use this function to get arguement in slice of interface with assertion type(int)

func GetAsInt(arguments []interface{}, idx int, defaultValue int32) int32
ParameterDescription
argumentsslice of interface{}
idxindex of target element
defaultValuereturn value if error
ResponseDescription
valuevalue of assertion type

Usage

testSlice := []interface{}{int32(0), "1"} // example
getInt := util.GetAsInt(testSlice, 0, int32(1))

GetAsLong

Description

Use this function to get arguement in slice of interface with assertion type(long)

func GetAsLong(arguments []interface{}, idx int, defaultValue int64) int64
ParameterDescription
argumentsslice of interface{}
idxindex of target element
defaultValuereturn value if error
ResponseDescription
valuevalue of assertion type

Usage

testSlice := []interface{}{int64(0), "1"} // example
getLong := util.GetAsLong(testSlice, 0, int64(1))

GetAsFloat

Description

Use this function to get arguement in slice of interface with assertion type(float)

func GetAsFloat(arguments []interface{}, idx int, defaultValue float32) float32
ParameterDescription
argumentsslice of interface{}
idxindex of target element
defaultValuereturn value if error
ResponseDescription
valuevalue of assertion type

Usage

testSlice := []interface{}{float32(0.5), "1"} // example
getFloat := util.GetAsFloat(testSlice, 0, float32(0.0))

GetAsDouble

Description

Use this function to get arguement in slice of interface with assertion type(double)

func GetAsDouble(arguments []interface{}, idx int, defaultValue float64) float64
ParameterDescription
argumentsslice of interface{}
idxindex of target element
defaultValuereturn value if error
ResponseDescription
valuevalue of assertion type

Usage

testSlice := []interface{}{float64(0.5), "1"} // example
getDouble := util.GetAsDouble(testSlice, 0, float64(0.0))

GetAsString

Use this function to get arguement in slice of interface with assertion type(string)

func GetAsString(arguments []interface{}, idx int, defaultValue string) string
ParameterDescription
argumentsslice of interface{}
idxindex of target element
defaultValuereturn value if error
ResponseDescription
valuevalue of assertion type

Usage

testSlice := []interface{}{"0", 1} // example
getString := util.GetAsString(testSlice, 0, "0")

GetAsObject

Use this function to get arguement in slice of interface with assertion type(customized struct)

func GetAsObject(arguments []interface{}, idx int, defaultValue interface{}) interface{}
ParameterDescription
argumentsslice of interface{}
idxindex of target element
defaultValuereturn value if error
ResponseDescription
valuevalue of assertion type

Usage

type test struct {
	value string
}

testSlice := []interface{}{test{value: "test"}, "1"} //example
object := util.GetAsObject(testSlice, 0, test{})

DumpStacks

DumpStacks

Description

Use this function to get dump of stacks

func DumpStacks() string
ResponseDescription
stringstring of dump stacks

Usage

dumpStacks := util.DumpStacks()
fmt.Printf("dumpStacks: %s \n", dumpStacks)

CurrentFunctionName

Description

Use this function to get current function name

func CurrentFunctionName() string
ResponseDescription
stringstring of current function name

Usage

name := util.CurrentFunctionName()
fmt.Printf("CurrentFunctionName: %s \n", name)

CurrentCallerName

Description

Use this function to get current caller name

func CurrentCallerName() string
ResponseDescription
stringstring of current caller name

Usage

name := util.CurrentCallerName()
fmt.Printf("CurrentCallerName: %s \n", name)

misc

GetCurrentDirectory

Description

Use this function to get the directory of go exe

func GetCurrentDirectory() (string, error)
ResponseDescription
stringcurrent directory of go exe
errgo error(nil when success)

Usage

directory, err := util.GetCurrentDirectory()
if err != nil {
    fmt.Println(err.Error())
}
fmt.Printf("Get current directory success, directory: %s \n", directory)

GetAppName

Description

Use this function to get the name of go application

func GetAppName() string
ResponseDescription
stringname of go application

Usage

appName := util.GetAppName()
fmt.Printf("Get app name success, appName: %s \n", appName)

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RandomUUIDString helps to generate a random UUID-V4 string.
RandString generates a random string with length 'n'.

# Structs

No description provided by the author