github.com/wangzhucn/terraform@v0.6.7-0.20151109233120-4eea011b56b3/depgraph/dependency.go (about) 1 package depgraph 2 3 import ( 4 "fmt" 5 6 "github.com/hashicorp/terraform/digraph" 7 ) 8 9 // Dependency is used to create a directed edge between two nouns. 10 // One noun may depend on another and provide version constraints 11 // that cannot be violated 12 type Dependency struct { 13 Name string 14 Meta interface{} 15 Constraints []Constraint 16 Source *Noun 17 Target *Noun 18 } 19 20 // Constraint is used by dependencies to allow arbitrary constraints 21 // between nouns 22 type Constraint interface { 23 Satisfied(head, tail *Noun) (bool, error) 24 } 25 26 // Head returns the source, or dependent noun 27 func (d *Dependency) Head() digraph.Node { 28 return d.Source 29 } 30 31 // Tail returns the target, or depended upon noun 32 func (d *Dependency) Tail() digraph.Node { 33 return d.Target 34 } 35 36 func (d *Dependency) GoString() string { 37 return fmt.Sprintf( 38 "*Dependency{Name: %s, Source: %s, Target: %s}", 39 d.Name, 40 d.Source.Name, 41 d.Target.Name) 42 } 43 44 func (d *Dependency) String() string { 45 return d.Name 46 }