luci: go.chromium.org/luci/client/internal/common Index | Examples | Files

package common

import "go.chromium.org/luci/client/internal/common"

Package common implements code and utilities shared across all packages in client/.

Index

Examples

Package Files

concurrent.go doc.go filesystem_view.go flags.go types.go utils.go

func IsTerminal Uses

func IsTerminal(out io.Writer) bool

IsTerminal returns true if the specified io.Writer is a terminal.

func WalkFuncSkipFile Uses

func WalkFuncSkipFile(file os.FileInfo) error

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.

type FilesystemView Uses

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. It also hides any paths which match a blacklist entry.

func NewFilesystemView Uses

func NewFilesystemView(root string, blacklist []string) (FilesystemView, error)

NewFilesystemView returns a FilesystemView based on the supplied root and blacklist, or an error if blacklist contains a bad pattern.

root is the the base path used by RelativePath to calculate relative paths.

blacklist is a list of globs of files to ignore. See RelativePath for more information.

func (FilesystemView) NewSymlinkedView Uses

func (ff FilesystemView) NewSymlinkedView(source, linkname string) FilesystemView

NewSymlinkedView returns a filesystem view from a symlinked directory within itself.

func (FilesystemView) RelativePath Uses

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 blacklist entry.

Blacklist globs are matched against the entirety of each of:

* the path relative to the FilesystemView root.
* the basename return by filepath.Base(path).

See filepath.Match for details about the format of blacklist globs.

type Flags Uses

type Flags struct {
    Quiet     bool
    Verbose   bool
    TracePath string
}

Flags contains values parsed from command line arguments.

func (*Flags) Init Uses

func (d *Flags) Init(f *flag.FlagSet)

Init registers flags in a given flag set.

func (*Flags) MakeLoggingContext Uses

func (d *Flags) MakeLoggingContext(out io.Writer) context.Context

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.

func (*Flags) Parse Uses

func (d *Flags) Parse() error

Parse applies changes specified by command line flags.

func (*Flags) StartTracing Uses

func (d *Flags) StartTracing() (io.Closer, error)

StartTracing enables tracing and returns a closer that must be called on process termination.

type GoroutinePool Uses

type GoroutinePool struct {
    // contains filtered or unexported fields
}

GoroutinePool executes at a limited number of jobs concurrently, queueing others.

func NewGoroutinePool Uses

func NewGoroutinePool(ctx context.Context, maxConcurrentJobs int) *GoroutinePool

NewGoroutinePool creates a new GoroutinePool running at most maxConcurrentJobs concurrent operations.

Code:

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 Uses

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 Uses

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 Uses

type GoroutinePriorityPool struct {
    // contains filtered or unexported fields
}

GoroutinePriorityPool executes a limited number of jobs concurrently, queueing others.

func NewGoroutinePriorityPool Uses

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 Uses

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 Uses

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.

type Strings Uses

type Strings []string

Strings accumulates string values from repeated flags.

Use with flag.Var to accumulate values from "-flag s1 -flag s2".

func (*Strings) Set Uses

func (c *Strings) Set(value string) error

Set is needed to implements flag.Var interface.

func (*Strings) String Uses

func (c *Strings) String() string

Package common imports 15 packages (graph) and is imported by 16 packages. Updated 2019-12-06. Refresh now. Tools for package owners.