lang: interfaces, funcs: Implement fmt.Stringer for functions
This adds the requirement that all function implementations provider a String() string method so that these can be used as vertices in the pgraph library. If we eventually move to generics for the pgraph DAG, then this might not matter, but it's not bad that these have names either.
This commit is contained in:
@@ -25,6 +25,11 @@ import (
|
||||
"github.com/purpleidea/mgmt/util/errwrap"
|
||||
)
|
||||
|
||||
const (
|
||||
// CompositeFuncName is the unique name identifier for this function.
|
||||
CompositeFuncName = "composite"
|
||||
)
|
||||
|
||||
// CompositeFunc is a function that passes through the value it receives. It is
|
||||
// used to take a series of inputs to a list, map or struct, and return that
|
||||
// value as a stream that depends on those inputs. It helps the list, map, and
|
||||
@@ -40,6 +45,12 @@ type CompositeFunc struct {
|
||||
closeChan chan struct{}
|
||||
}
|
||||
|
||||
// String returns a simple name for this function. This is needed so this struct
|
||||
// can satisfy the pgraph.Vertex interface.
|
||||
func (obj *CompositeFunc) String() string {
|
||||
return CompositeFuncName
|
||||
}
|
||||
|
||||
// Validate makes sure we've built our struct properly.
|
||||
func (obj *CompositeFunc) Validate() error {
|
||||
if obj.Type == nil {
|
||||
|
||||
Reference in New Issue
Block a user