Documentation ¶
Overview ¶
Package common implements code and utilities shared across all packages in client/.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsTerminal ¶
IsTerminal returns true if the specified io.Writer is a terminal.
func WalkFuncSkipFile ¶
WalkFuncSkipFile is a helper for implementations of filepath.WalkFunc. The value that it returns may in turn be returned by the WalkFunc implementatiton to indicate that file should be skipped.
Types ¶
type FilesystemView ¶
type FilesystemView struct {
// contains filtered or unexported fields
}
FilesystemView provides a filtered "view" of a filesystem. It translates absolute paths to relative paths based on its configured root path.
func NewFilesystemView ¶
func NewFilesystemView(root string, ignoredPathRe string) (FilesystemView, error)
NewFilesystemView returns a FilesystemView based on the supplied root, or an error if ignoredPathRe contains a bad pattern.
root is the the base path used by RelativePath to calculate relative paths.
ignoredPathRe is a regular expression string. Note that this is NOT a full string match, so "foo/.*" may match "bar/foo/xyz". Prepend ^ explicitly if you need to match a path that starts with the pattern. Similarly, append $ if necessary.
func (FilesystemView) NewSymlinkedView ¶
func (ff FilesystemView) NewSymlinkedView(source, linkname string) FilesystemView
NewSymlinkedView returns a filesystem view from a symlinked directory within itself.
func (FilesystemView) RelativePath ¶
func (ff FilesystemView) RelativePath(path string) (string, error)
RelativePath returns a version of path which is relative to the FilesystemView root or an empty string if path matches a ignored path filter.
type Flags ¶
Flags contains values parsed from command line arguments.
func (*Flags) MakeLoggingContext ¶
MakeLoggingContext makes a luci-go/common/logging compatible context using gologger onto the given writer.
The default logging level will be Info, with Warning and Debug corresponding to quiet/verbose respectively.
type GoroutinePool ¶
type GoroutinePool struct {
// contains filtered or unexported fields
}
GoroutinePool executes at a limited number of jobs concurrently, queueing others.
func NewGoroutinePool ¶
func NewGoroutinePool(ctx context.Context, maxConcurrentJobs int) *GoroutinePool
NewGoroutinePool creates a new GoroutinePool running at most maxConcurrentJobs concurrent operations.
Example ¶
ctx, cancel := context.WithCancel(context.Background()) defer cancel() pool := NewGoroutinePool(ctx, 2) for _, s := range []string{"knock!", "knock!"} { s := s // Create a new s for closure. pool.Schedule(func() { fmt.Print(s) }, nil) } if pool.Wait() == nil { fmt.Printf("\n") } cancel() pool.Schedule(func() {}, func() { fmt.Printf("canceled because %s\n", ctx.Err()) }) err := pool.Wait() fmt.Printf("all jobs either executed or canceled (%s)\n", err)
Output: knock!knock! canceled because context canceled all jobs either executed or canceled (context canceled)
func (*GoroutinePool) Schedule ¶
func (g *GoroutinePool) Schedule(job, onCanceled func())
Schedule adds a new job for execution as a separate goroutine.
If the GoroutinePool context is canceled, onCanceled is called instead. It is fine to pass nil as onCanceled.
func (*GoroutinePool) Wait ¶
func (g *GoroutinePool) Wait() error
Wait blocks until all started jobs are done, or the context is canceled.
Returns nil if all jobs have been executed, or the error if the associated context is canceled.
type GoroutinePriorityPool ¶
type GoroutinePriorityPool struct {
// contains filtered or unexported fields
}
GoroutinePriorityPool executes a limited number of jobs concurrently, queueing others.
func NewGoroutinePriorityPool ¶
func NewGoroutinePriorityPool(ctx context.Context, maxConcurrentJobs int) *GoroutinePriorityPool
NewGoroutinePriorityPool creates a new goroutine pool with at most maxConcurrentJobs.
Each task is run according to the priority of each item.
func (*GoroutinePriorityPool) Schedule ¶
func (g *GoroutinePriorityPool) Schedule(priority int64, job, onCanceled func())
Schedule adds a new job for execution as a separate goroutine.
If the GoroutinePriorityPool is canceled, onCanceled is called instead. It is fine to pass nil as onCanceled. Smaller values of priority imply earlier execution.
The lower the priority value, the higher the priority of the item.
func (*GoroutinePriorityPool) Wait ¶
func (g *GoroutinePriorityPool) Wait() error
Wait blocks until all started jobs are done, or the context is canceled.
Returns nil if all jobs have been executed, or the error if the associated context is canceled.