Version: v0.0.0-...-11d6bb4 Latest Latest

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

Go to latest
Published: May 26, 2023 License: Apache-2.0 Imports: 23 Imported by: 556




View Source
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"


View Source
var HashAlg = map[string]func() hash.Hash{
	SHA1:   sha1.New,
	SHA256: sha256.New,

HashAlg used to get correct alg for hash


func ConvertMapToStruct

func ConvertMapToStruct(object interface{}, values interface{}) error

ConvertMapToStruct is used to fill the specified struct with map.

func CronParser

func CronParser() cronlib.Parser

CronParser returns the parser of cron string with format of "* * * * * *"

func Encrypt

func Encrypt(content string, salt string, encrptAlg string) string

Encrypt encrypts the content with salt

func FindNamedMatches

func FindNamedMatches(regex *regexp.Regexp, str string) map[string]string

FindNamedMatches returns named matches of the regexp groups

func GenerateRandomString

func GenerateRandomString() string

GenerateRandomString generate a random string with 32 byte length

func GenerateRandomStringWithLen

func GenerateRandomStringWithLen(length int) string

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

func IsContainIllegalChar(s string, illegalChar []string) bool

IsContainIllegalChar ...

func IsIllegalLength

func IsIllegalLength(s string, min int, max int) bool

IsIllegalLength ...

func MostMatchSorter

func MostMatchSorter(a, b string, matchWord string) bool

func NextSchedule

func NextSchedule(cron string, curTime time.Time) time.Time

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

func ParseEndpoint(endpoint string) (*url.URL, error)

ParseEndpoint parses endpoint to a URL

func ParseJSONInt

func ParseJSONInt(value interface{}) (int, bool)

ParseJSONInt ...

func ParseProjectIDOrName

func ParseProjectIDOrName(value interface{}) (int64, string, error)

ParseProjectIDOrName parses value to ID(int64) or name(string)

func ParseRepository

func ParseRepository(repository string) (project, rest string)

ParseRepository splits a repository into two parts: project and rest

func ParseTimeStamp

func ParseTimeStamp(timestamp string) (*time.Time, error)

ParseTimeStamp parse timestamp to time

func ReversibleDecrypt

func ReversibleDecrypt(str, key string) (string, error)

ReversibleDecrypt decrypts the str with aes/base64 or base 64 depending on "header"

func ReversibleEncrypt

func ReversibleEncrypt(str, key string) (string, error)

ReversibleEncrypt encrypts the str with aes/base64

func SafeCastBool

func SafeCastBool(value interface{}) bool

SafeCastBool --

func SafeCastFloat64

func SafeCastFloat64(value interface{}) float64

SafeCastFloat64 --

func SafeCastInt

func SafeCastInt(value interface{}) int

SafeCastInt --

func SafeCastString

func SafeCastString(value interface{}) string

SafeCastString -- cast a object to string saftely

func TestTCPConn

func TestTCPConn(addr string, timeout, interval int) error

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

func TrimLower

func TrimLower(str string) string

TrimLower ...


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


Path Synopsis

Jump to

Keyboard shortcuts

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