Documentation ¶
Index ¶
- Constants
- Variables
- func ConvertMapToStruct(object interface{}, values interface{}) error
- func CronParser() cronlib.Parser
- func Encrypt(content string, salt string, encryptAlg 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 IsIllegalLength(s string, min int, max int) bool
- func IsLocalPath(path string) bool
- func MostMatchSorter(a, b string, matchWord string) bool
- func NextSchedule(cron string, curTime time.Time) time.Time
- 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
- func ValidateCronString(cron string) error
- 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 CronParser ¶
CronParser returns the parser of cron string with format of "* * * * * *"
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 IsLocalPath ¶
IsLocalPath checks if path is local, includes the empty path
func MostMatchSorter ¶
MostMatchSorter is a sorter for the most match, usually invoked in sort Less function usage:
sort.Slice(input, func(i, j int) bool { return MostMatchSorter(input[i].GroupName, input[j].GroupName, matchWord) })
a is the field to be used for sorting, b is the other field, matchWord is the word to be matched the return value is true if a is less than b for example, search with "user", input is {"harbor_user", "user", "users, "admin_user"} it returns with this order {"user", "users", "admin_user", "harbor_user"}
func NextSchedule ¶
NextSchedule return next scheduled time with a cron string and current time provided the cron string could contain 6 tokens if the cron string is invalid, it returns a zero time
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 an object to string safely
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 retrying after failure, in second
func ValidateCronString ¶
ValidateCronString check whether it is a valid cron string and whether the 1st field (indicating Seconds of time) of the cron string is a fixed value of 0 or not
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 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