Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertMapToStruct(object interface{}, values interface{}) error
- func Encrypt(content string, salt string, encrptAlg string) string
- func FindNamedMatches(regex *regexp.Regexp, str string) map[string]string
- func GenerateRandomString() string
- func GenerateRandomStringWithLen(length int) string
- func GetStrValueOfAnyType(value interface{}) string
- func IsContainIllegalChar(s string, illegalChar []string) bool
- func IsIllegalLength(s string, min int, max int) bool
- func ParseEndpoint(endpoint string) (*url.URL, error)
- func ParseJSONInt(value interface{}) (int, bool)
- func ParseProjectIDOrName(value interface{}) (int64, string, error)
- func ParseRepository(repository string) (project, rest string)
- func ParseTimeStamp(timestamp string) (*time.Time, error)
- func ReversibleDecrypt(str, key string) (string, error)
- func ReversibleEncrypt(str, key string) (string, error)
- func SafeCastBool(value interface{}) bool
- func SafeCastFloat64(value interface{}) float64
- func SafeCastInt(value interface{}) int
- func SafeCastString(value interface{}) string
- func TestTCPConn(addr string, timeout, interval int) error
- func TrimLower(str string) string
- type LimitedConcurrentRunner
- type PassportsPool
Constants ¶
const ( // EncryptHeaderV1 ... EncryptHeaderV1 = "<enc-v1>" // SHA1 is the name of sha1 hash alg SHA1 = "sha1" // SHA256 is the name of sha256 hash alg SHA256 = "sha256" )
Variables ¶
HashAlg used to get correct alg for hash
Functions ¶
func ConvertMapToStruct ¶
func ConvertMapToStruct(object interface{}, values interface{}) error
ConvertMapToStruct is used to fill the specified struct with map.
func FindNamedMatches ¶
FindNamedMatches returns named matches of the regexp groups
func GenerateRandomString ¶
func GenerateRandomString() string
GenerateRandomString generate a random string with 32 byte length
func GenerateRandomStringWithLen ¶
GenerateRandomStringWithLen generates a random string with length
func GetStrValueOfAnyType ¶
func GetStrValueOfAnyType(value interface{}) string
GetStrValueOfAnyType return string format of any value, for map, need to convert to json
func IsContainIllegalChar ¶
IsContainIllegalChar ...
func ParseEndpoint ¶
ParseEndpoint parses endpoint to a URL
func ParseProjectIDOrName ¶
ParseProjectIDOrName parses value to ID(int64) or name(string)
func ParseRepository ¶
ParseRepository splits a repository into two parts: project and rest
func ParseTimeStamp ¶
ParseTimeStamp parse timestamp to time
func ReversibleDecrypt ¶
ReversibleDecrypt decrypts the str with aes/base64 or base 64 depending on "header"
func ReversibleEncrypt ¶
ReversibleEncrypt encrypts the str with aes/base64
func SafeCastString ¶
func SafeCastString(value interface{}) string
SafeCastString -- cast a object to string saftely
func TestTCPConn ¶
TestTCPConn tests TCP connection timeout: the total time before returning if something is wrong with the connection, in second interval: the interval time for retring after failure, in second
Types ¶
type LimitedConcurrentRunner ¶
type LimitedConcurrentRunner interface { // AddTask adds a task to run AddTask(task func() error) // Wait waits all the tasks to be finished, returns error if the any of the tasks gets error Wait() (err error) // Cancel cancels all tasks, tasks that already started will continue to run Cancel(err error) }
LimitedConcurrentRunner is used to run tasks, but limit the max concurrency.
func NewLimitedConcurrentRunner ¶
func NewLimitedConcurrentRunner(limit int) LimitedConcurrentRunner
NewLimitedConcurrentRunner creates a runner
type PassportsPool ¶
type PassportsPool interface { // Apply applies a passport from the pool. Apply() bool // Revoke revokes a passport to the pool Revoke() bool }
PassportsPool holds a given number of passports, they can be applied or be revoked. PassportsPool is used to control the concurrency of tasks, the pool size determine the max concurrency. When users want to start a goroutine to perform some task, they must apply a passport firstly, and after finish the task, the passport must be revoked.
func NewPassportsPool ¶
func NewPassportsPool(size int, stopped <-chan struct{}) PassportsPool
NewPassportsPool creates a passports pool with given size