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:
@@ -27,9 +27,14 @@ import (
|
||||
"github.com/purpleidea/mgmt/util/errwrap"
|
||||
)
|
||||
|
||||
func init() {
|
||||
const (
|
||||
// MapFuncName is the name this function is registered as.
|
||||
// XXX: rename to map once our parser sees a function name and not a type
|
||||
funcs.ModuleRegister(ModuleName, "xmap", func() interfaces.Func { return &MapFunc{} }) // must register the func and name
|
||||
MapFuncName = "xmap"
|
||||
)
|
||||
|
||||
func init() {
|
||||
funcs.ModuleRegister(ModuleName, MapFuncName, func() interfaces.Func { return &MapFunc{} }) // must register the func and name
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -62,6 +67,12 @@ type MapFunc 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 *MapFunc) String() string {
|
||||
return MapFuncName
|
||||
}
|
||||
|
||||
// ArgGen returns the Nth arg name for this function.
|
||||
func (obj *MapFunc) ArgGen(index int) (string, error) {
|
||||
seq := []string{argNameInputs, argNameFunction} // inverted for pretty!
|
||||
|
||||
Reference in New Issue
Block a user