Documentation ¶
Overview ¶
Package utils ...
Index ¶
- Variables
- func AbsolutePaths(paths []string) []string
- 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{}
- func EscapeGoString(s string) string
- func Exec(line string, rest ...string) string
- func ExecLine(std bool, line string, rest ...string) string
- 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 Noop()
- func OutputFile(p string, data interface{}) error
- func Pause()
- func RandString(l 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)
- func SplicePngVertical(files []ImgWithBox, format proto.PageCaptureScreenshotFormat, opt *ImgOption) ([]byte, error)
- func UseNode(std bool)
- type IdleCounter
- type ImgOption
- type ImgProcessor
- type ImgWithBox
- type Log
- type Logger
- type MaxSleepCountError
- type Sleeper
Constants ¶
This section is empty.
Variables ¶
var InContainer = FileExists("/.dockerenv") || FileExists("/.containerenv") || os.Getenv("KUBERNETES_SERVICE_HOST") != ""
InContainer will be true if is inside container environment, such as docker.
var Panic = func(v interface{}) { panic(v) }
Panic is the same as the built-in panic.
var TestEnvs = map[string]string{
"GODEBUG": "tracebackancestors=100",
}
TestEnvs for testing.
Functions ¶
func AbsolutePaths ¶ added in v0.109.0
AbsolutePaths returns absolute paths of files in current working directory.
func All ¶ added in v0.52.0
func All(actions ...func()) func()
All runs all actions concurrently, returns the wait function for all actions.
func DefaultBackoff ¶ added in v0.52.0
DefaultBackoff algorithm: A(n) = A(n-1) * random[1.9, 2.1).
func EscapeGoString ¶ added in v0.62.0
EscapeGoString not using encoding like base64 or gzip because of they will make git diff every large for small change.
func FileExists ¶ added in v0.52.0
FileExists checks if file exists, only for file, not for dir.
func FormatCLIArgs ¶ added in v0.106.0
FormatCLIArgs into one line string.
func MustToJSON ¶ added in v0.52.0
func MustToJSON(data interface{}) string
MustToJSON encode data to json string.
func MustToJSONBytes ¶ added in v0.52.0
func MustToJSONBytes(data interface{}) []byte
MustToJSONBytes encode data to json bytes.
func OutputFile ¶ added in v0.52.0
OutputFile auto creates file if not exists, it will try to detect the data type and auto output binary, string or json.
func RandString ¶ added in v0.52.0
RandString generate random string with specified string length.
func ReadString ¶ added in v0.52.0
ReadString reads file as string.
func Sleep ¶ added in v0.52.0
func Sleep(seconds float64)
Sleep the goroutine for specified seconds, such as 2.3 seconds.
func SplicePngVertical ¶ added in v0.114.7
func SplicePngVertical(files []ImgWithBox, format proto.PageCaptureScreenshotFormat, opt *ImgOption) ([]byte, error)
SplicePngVertical 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.
Types ¶
type IdleCounter ¶ added in v0.69.0
type IdleCounter struct {
// contains filtered or unexported fields
}
IdleCounter is similar to sync.WaitGroup but it only resolves if no jobs for specified duration.
func NewIdleCounter ¶ added in v0.69.0
func NewIdleCounter(d time.Duration) *IdleCounter
NewIdleCounter ...
func (*IdleCounter) Wait ¶ added in v0.69.0
func (de *IdleCounter) Wait(ctx context.Context)
Wait ...
type ImgOption ¶ added in v0.114.7
type ImgOption struct {
Quality int
}
ImgOption is the option for image processing.
type ImgProcessor ¶ added in v0.114.7
type ImgProcessor interface { Encode(img image.Image, opt *ImgOption) ([]byte, error) Decode(file io.Reader) (image.Image, error) }
ImgProcessor is the interface for image processing.
func NewImgProcessor ¶ added in v0.114.7
func NewImgProcessor(format proto.PageCaptureScreenshotFormat) (ImgProcessor, error)
NewImgProcessor create a ImgProcessor by the format.
type ImgWithBox ¶ added in v0.114.7
ImgWithBox is a image with a box, if the box is nil, it means the whole image.
type Log ¶ added in v0.70.0
type Log func(msg ...interface{})
Log type for Println.
func MultiLogger ¶ added in v0.74.0
MultiLogger is similar to https://golang.org/pkg/io/#MultiWriter
type Logger ¶ added in v0.70.0
type Logger interface {
// Same as fmt.Printf
Println(vs ...interface{})
}
Logger interface.
type MaxSleepCountError ¶ added in v0.114.8
type MaxSleepCountError struct { // Max count Max int }
MaxSleepCountError type.
func (*MaxSleepCountError) Error ¶ added in v0.114.8
func (e *MaxSleepCountError) Error() string
Error interface.
func (*MaxSleepCountError) Is ¶ added in v0.114.8
func (e *MaxSleepCountError) Is(err error) bool
Is interface.
type Sleeper ¶ added in v0.52.0
Sleeper sleeps the current goroutine for sometime, returns the reason to wake, if ctx is done release resource.
func BackoffSleeper ¶ added in v0.52.0
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 ¶ added in v0.52.0
CountSleeper wakes immediately. When counts to the max returns *ErrMaxSleepCount.
func EachSleepers ¶ added in v0.92.0
EachSleepers returns a sleeper wakes up when each sleeper is awake. If a sleeper returns error, it will wake up immediately.
func RaceSleepers ¶ added in v0.92.0
RaceSleepers returns a sleeper wakes up when one of the sleepers wakes.
Directories ¶
Path | Synopsis |
---|---|
check-issue
module
|
|
Package main A helper to run go test on CI with the right environment variables.
|
Package main A helper to run go test on CI with the right environment variables. |
Package main ...
|
Package main ... |
Package main ...
|
Package main ... |
Package main ...
|
Package main ... |
Package main ...
|
Package main ... |
Package main It helps to launcher a transparent shell under the current shell with some extra environment variables that are required by rod testing.
|
Package main It helps to launcher a transparent shell under the current shell with some extra environment variables that are required by rod testing. |
Package main ...
|
Package main ... |