{"modulePath":"github.com/GoCodeAlone/rod","version":"v0.116.3","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package utils\n\nPackage utils ...\n\n## Variables\n\n```go\nvar InContainer = FileExists(\"/.dockerenv\") || FileExists(\"/.containerenv\") ||\n\tos.Getenv(\"KUBERNETES_SERVICE_HOST\") != \"\"\n```\nInContainer will be true if is inside container environment, such as docker.\n\n```go\nvar Panic = func(v interface{}) { panic(v) }\n```\nPanic is the same as the built-in panic.\n\n```go\nvar TestEnvs = map[string]string{\n\t\"GODEBUG\": \"tracebackancestors=100\",\n}\n```\nTestEnvs for testing.\n\n## Functions\n\n```go\nfunc AbsolutePaths(paths []string) []string\n```\nAbsolutePaths returns absolute paths of files in current working directory.\n\n```go\nfunc All(actions ...func()) func()\n```\nAll runs all actions concurrently, returns the wait function for all actions.\n\n```go\nfunc CropImage(bin []byte, quality, x, y, width, height int) ([]byte, error)\n```\nCropImage by the specified box, quality is only for jpeg bin.\n\n```go\nfunc DefaultBackoff(interval time.Duration) time.Duration\n```\nDefaultBackoff algorithm: A(n) = A(n-1) \\* random\\[1.9, 2.1).\n\n```go\nfunc Dump(list ...interface{}) string\n```\nDump values for debugging.\n\n```go\nfunc E(args ...interface{}) []interface{}\n```\nE if the last arg is error, panic it.\n\n```go\nfunc EscapeGoString(s string) string\n```\nEscapeGoString not using encoding like base64 or gzip because of they will make git diff every large for small change.\n\n```go\nfunc Exec(line string, rest ...string) string\n```\nExec command.\n\n```go\nfunc ExecLine(std bool, line string, rest ...string) string\n```\nExecLine of command.\n\n```go\nfunc FileExists(path string) bool\n```\nFileExists checks if file exists, only for file, not for dir.\n\n```go\nfunc FormatCLIArgs(args []string) string\n```\nFormatCLIArgs into one line string.\n\n```go\nfunc Mkdir(path string) error\n```\nMkdir makes dir recursively.\n\n```go\nfunc MustToJSON(data interface{}) string\n```\nMustToJSON encode data to json string.\n\n```go\nfunc MustToJSONBytes(data interface{}) []byte\n```\nMustToJSONBytes encode data to json bytes.\n\n```go\nfunc Noop()\n```\nNoop does nothing.\n\n```go\nfunc OutputFile(p string, data interface{}) error\n```\nOutputFile auto creates file if not exists, it will try to detect the data type and auto output binary, string or json.\n\n```go\nfunc Pause()\n```\nPause the goroutine forever.\n\n```go\nfunc RandString(l int) string\n```\nRandString generate random string with specified string length.\n\n```go\nfunc ReadString(p string) (string, error)\n```\nReadString reads file as string.\n\n```go\nfunc Retry(ctx context.Context, s Sleeper, fn func() (stop bool, err error)) error\n```\nRetry fn and sleeper until fn returns true or s returns error.\n\n```go\nfunc S(tpl string, params ...interface{}) string\n```\nS Template render, the params is key-value pairs.\n\n```go\nfunc Sleep(seconds float64)\n```\nSleep the goroutine for specified seconds, such as 2.3 seconds.\n\n```go\nfunc SplicePngVertical(files []ImgWithBox, format proto.PageCaptureScreenshotFormat, opt *ImgOption) ([]byte, error)\n```\nSplicePngVertical splice png vertically, if there is only one image, it will return the image directly. Only support png and jpeg format yet, webP is not supported because no suitable processing library was found in golang.\n\n```go\nfunc UseNode(std bool)\n```\nUseNode installs Node.js and set the bin path to PATH env var.\n\n## Types\n\n```go\ntype IdleCounter struct {\n\t// contains filtered or unexported fields\n}\n```\nIdleCounter is similar to sync.WaitGroup but it only resolves if no jobs for specified duration.\n\n```go\nfunc NewIdleCounter(d time.Duration) *IdleCounter\n```\nNewIdleCounter ...\n\n```go\nfunc (de *IdleCounter) Add()\n```\nAdd ...\n\n```go\nfunc (de *IdleCounter) Done()\n```\nDone ...\n\n```go\nfunc (de *IdleCounter) Wait(ctx context.Context)\n```\nWait ...\n\n```go\ntype ImgOption struct {\n\tQuality int\n}\n```\nImgOption is the option for image processing.\n\n```go\ntype ImgProcessor interface {\n\tEncode(img image.Image, opt *ImgOption) ([]byte, error)\n\tDecode(file io.Reader) (image.Image, error)\n}\n```\nImgProcessor is the interface for image processing.\n\n```go\nfunc NewImgProcessor(format proto.PageCaptureScreenshotFormat) (ImgProcessor, error)\n```\nNewImgProcessor create a ImgProcessor by the format.\n\n```go\ntype ImgWithBox struct {\n\tImg []byte\n\tBox *image.Rectangle\n}\n```\nImgWithBox is a image with a box, if the box is nil, it means the whole image.\n\n```go\ntype Log func(msg ...interface{})\n```\nLog type for Println.\n\n```go\nfunc MultiLogger(list ...Logger) Log\n```\nMultiLogger is similar to [https://golang.org/pkg/io/#MultiWriter](https://golang.org/pkg/io/#MultiWriter)\n\n```go\nfunc (l Log) Println(msg ...interface{})\n```\nPrintln interface.\n\n```go\ntype Logger interface {\n\t// Same as fmt.Printf\n\tPrintln(vs ...interface{})\n}\n```\nLogger interface.\n\n```go\nvar LoggerQuiet Logger = Log(func(_ ...interface{}) {})\n```\nLoggerQuiet does nothing.\n\n```go\ntype MaxSleepCountError struct {\n\t// Max count\n\tMax int\n}\n```\nMaxSleepCountError type.\n\n```go\nfunc (e *MaxSleepCountError) Error() string\n```\nError interface.\n\n```go\nfunc (e *MaxSleepCountError) Is(err error) bool\n```\nIs interface.\n\n```go\ntype Sleeper func(context.Context) error\n```\nSleeper sleeps the current goroutine for sometime, returns the reason to wake, if ctx is done release resource.\n\n```go\nfunc BackoffSleeper(initInterval, maxInterval time.Duration, algorithm func(time.Duration) time.Duration) Sleeper\n```\nBackoffSleeper 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.\n\n```go\nfunc CountSleeper(max int) Sleeper\n```\nCountSleeper wakes immediately. When counts to the max returns \\*ErrMaxSleepCount.\n\n```go\nfunc EachSleepers(list ...Sleeper) Sleeper\n```\nEachSleepers returns a sleeper wakes up when each sleeper is awake. If a sleeper returns error, it will wake up immediately.\n\n```go\nfunc RaceSleepers(list ...Sleeper) Sleeper\n```\nRaceSleepers returns a sleeper wakes up when one of the sleepers wakes.\n\n","path":"github.com/GoCodeAlone/rod/lib/utils","name":"utils","synopsis":"Package utils ...","isRedistributable":true}
