Documentation ¶
Index ¶
- Variables
- func All(actions ...func()) func()
- func CropImage(bin []byte, quality, x, y, width, height int) ([]byte, error)
- func DefaultBackoff(interval time.Duration) time.Duration
- func Dump(list ...interface{}) string
- func E(args ...interface{}) ([]interface{}, error)
- func EscapeGoString(s string) string
- func Exec(line string, rest ...string) (string, error)
- func ExecLine(std bool, line string, rest ...string) (string, error)
- func FileExists(path string) bool
- func FormatCLIArgs(args []string) string
- func Mkdir(path string) error
- func MustToJSON(data interface{}) string
- func MustToJSONBytes(data interface{}) []byte
- func OutputFile(p string, data interface{}) error
- func Pause()
- func RandString(len int) string
- func ReadString(p string) (string, error)
- func Retry(ctx context.Context, s Sleeper, fn func() (stop bool, err error)) error
- func S(tpl string, params ...interface{}) string
- func Sleep(seconds float64)
- type ErrMaxSleepCount
- type IdleCounter
- type Log
- type Logger
- type Sleeper
Constants ¶
This section is empty.
Variables ¶
var InContainer = FileExists("/.dockerenv") || FileExists("/.containerenv")
InContainer will be true if is inside container environment, such as docker
Functions ¶
func All ¶
func All(actions ...func()) func()
All runs all actions concurrently, returns the wait function for all actions.
func DefaultBackoff ¶
DefaultBackoff algorithm: A(n) = A(n-1) * random[1.9, 2.1)
func E ¶
func E(args ...interface{}) ([]interface{}, error)
E if the last arg is error, return error
func EscapeGoString ¶
EscapeGoString not using encoding like base64 or gzip because of they will make git diff every large for small change
func FileExists ¶
FileExists checks if file exists, only for file, not for dir
func MustToJSONBytes ¶
func MustToJSONBytes(data interface{}) []byte
MustToJSONBytes encode data to json bytes
func OutputFile ¶
OutputFile auto creates file if not exists, it will try to detect the data type and auto output binary, string or json
func RandString ¶
RandString generate random string with specified string length
Types ¶
type IdleCounter ¶
type IdleCounter struct {
// contains filtered or unexported fields
}
IdleCounter is similar to sync.WaitGroup but it only resolves if no jobs for specified duration.
type Log ¶
type Log func(msg ...interface{})
Log type for Println
func MultiLogger ¶
MultiLogger is similar to https://golang.org/pkg/io/#MultiWriter
type Logger ¶
type Logger interface {
// Same as fmt.Printf
Println(...interface{})
}
Logger interface
type Sleeper ¶
Sleeper sleeps the current gouroutine for sometime, returns the reason to wake, if ctx is done release resource
func BackoffSleeper ¶
func BackoffSleeper(initInterval, maxInterval time.Duration, algorithm func(time.Duration) time.Duration) Sleeper
BackoffSleeper returns a sleeper that sleeps in a backoff manner every time get called. The sleep interval of the sleeper will grow from initInterval to maxInterval by the specified algorithm, then use maxInterval as the interval. If maxInterval is not greater than 0, the sleeper will wake immediately. If algorithm is nil, DefaultBackoff will be used.
func CountSleeper ¶
CountSleeper wakes immediately. When counts to the max returns *ErrMaxSleepCount
func EachSleepers ¶
EachSleepers returns a sleeper wakes up when each sleeper is awake. If a sleeper returns error, it will wake up immediately.
func RaceSleepers ¶
RaceSleepers returns a sleeper wakes up when one of the sleepers wakes.
Directories ¶
Path | Synopsis |
---|---|
The .github/workflows/docker.yml uses it as an github action and run it like this: DOCKER_TOKEN=$TOKEN go run ./lib/utils/docker $GITHUB_REF
|
The .github/workflows/docker.yml uses it as an github action and run it like this: DOCKER_TOKEN=$TOKEN go run ./lib/utils/docker $GITHUB_REF |