Documentation
¶
Overview ¶
Package graph holds the utilities for building/maintaining the dependency graph and notifying on changes.
Index ¶
- Variables
- func OmitNonGo(path string) bool
- func OmitTest(path string) bool
- func OmitVendor(pkg *gb.Package) bool
- func WithCurrentDirectory(m *manager) error
- func WithFSNotify(m *manager) error
- func WithOutsideWorkDirFilter(m *manager) error
- type FileFilter
- type Interface
- type Observer
- type Option
- type PackageFilter
- type StringSet
Constants ¶
This section is empty.
Variables ¶
var DefaultOptions = []Option{WithCurrentDirectory, WithContext(&gb.Default), WithFSNotify, WithFileFilter(OmitTest, OmitNonGo), WithPackageFilter(OmitVendor), WithOutsideWorkDirFilter}
Functions ¶
func OmitNonGo ¶
OmitNonGo implements FileFilter to exclude non-Go files from triggering package change notifications.
func OmitTest ¶
OmitTests implements FileFilter to exclude Go test files from triggering package change notifications.
func OmitVendor ¶
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 ¶
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 ¶
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. }
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 ¶
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 ¶
WithWorkDir configures the graph to use the provided working directory.
type PackageFilter ¶
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.