graph

package
v0.0.0-...-a45dec3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2019 License: Apache-2.0 Imports: 8 Imported by: 3

Documentation

Overview

Package graph holds the utilities for building/maintaining the dependency graph and notifying on changes.

Index

Constants

This section is empty.

Variables

Functions

func OmitNonGo

func OmitNonGo(path string) bool

OmitNonGo implements FileFilter to exclude non-Go files from triggering package change notifications.

func OmitTest

func OmitTest(path string) bool

OmitTests implements FileFilter to exclude Go test files from triggering package change notifications.

func OmitVendor

func OmitVendor(pkg *gb.Package) bool

OmitVendor implements PackageFilter to exclude packages in the vendor directory.

func WithCurrentDirectory

func WithCurrentDirectory(m *manager) error

WithCurrentDirectory configures the working directory to be the current directory

func WithFSNotify

func WithFSNotify(m *manager) error

WithFSNotify configures the graph to use fsnotify to implement its watcher and error channel.

func WithOutsideWorkDirFilter

func WithOutsideWorkDirFilter(m *manager) error

WithOutsideWorkDirFilter configures the graph with a package filter that omits files outside of the configured working directory.

Types

type FileFilter

type FileFilter func(string) bool

FileFilter is the type of functions that determine whether to omit a particular file from triggering a package-level event.

type Interface

type Interface interface {
	// This adds a given importpath to the collection of roots that we are tracking.
	Add(importpath string) error

	// Shutdown stops tracking all Add'ed import paths for changes.
	Shutdown() error
}

Interface for manipulating the dependency graph.

func New

func New(obs Observer) (Interface, chan error, error)

New creates a new Interface for building up dependency graphs. It starts in the provided working directory, and will call the provided Observer for any changes.

The returned graph is empty, but new targets may be added via the returned Interface. New also returns any immediate errors, and a channel through which errors watching for changes in the dependencies will be returned until the graph is Shutdown.

// Create our empty graph
g, errCh, err := New(...)
if err != nil { ... }
// Cleanup when we're done.  This closes errCh.
defer g.Shutdown()
// Start tracking this target.
err := g.Add("github.com/mattmoor/warm-image/cmd/controller")
if err != nil { ... }
select {
  case err := <- errCh:
    // Handle errors that occur while watching the above target.
  case <-stopCh:
    // When some stop signal happens, we're done.
}

func NewWithOptions

func NewWithOptions(obs Observer, opts ...Option) (Interface, chan error, error)

type Observer

type Observer func(affected StringSet)

Observer is the type for the callback that will happen on changes. The callback is supplied with the transitive dependents (aka "affected targets") of the file that has changed.

type Option

type Option func(*manager) error

Option is used to mutate the underlying graph implementation during construction. Since the implementation's type is private this may only be implemented from within this package.

func WithContext

func WithContext(ctx *gb.Context) Option

WithContext configures the graph to use the provided Go build context.

func WithFileFilter

func WithFileFilter(ff ...FileFilter) Option

WithFileFilter configures the graph implementation with the provided file filters.

func WithPackageFilter

func WithPackageFilter(ff ...PackageFilter) Option

WithPackageFilter configures the graph implementation with the provided package filters.

func WithWorkDir

func WithWorkDir(workdir string) Option

WithWorkDir configures the graph to use the provided working directory.

type PackageFilter

type PackageFilter func(*gb.Package) bool

PackageFilter is the type of functions that determine whether to omit a particular Go package from the dependency graph.

type StringSet

type StringSet map[string]struct{}

StringSet is a simple abstraction for holding a collection of deduplicated strings.

func (*StringSet) Add

func (ss *StringSet) Add(key string)

Add inserts a provided key into our set.

func (*StringSet) Has

func (ss *StringSet) Has(key string) bool

Has returns whether the set contains the provided key.

func (StringSet) InOrder

func (ss StringSet) InOrder() []string

InOrder returns the keys of the set in the ordering determined by sort.Strings.

func (*StringSet) Remove

func (ss *StringSet) Remove(key string)

Remove deletes a provided key from our set.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL