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:
@@ -26,8 +26,13 @@ import (
|
||||
"github.com/purpleidea/mgmt/util/errwrap"
|
||||
)
|
||||
|
||||
const (
|
||||
// ReadFileAbsFuncName is the name this function is registered as.
|
||||
ReadFileAbsFuncName = "readfileabs"
|
||||
)
|
||||
|
||||
func init() {
|
||||
funcs.ModuleRegister(ModuleName, "readfileabs", func() interfaces.Func { return &ReadFileAbsFunc{} }) // must register the func and name
|
||||
funcs.ModuleRegister(ModuleName, ReadFileAbsFuncName, func() interfaces.Func { return &ReadFileAbsFunc{} }) // must register the func and name
|
||||
}
|
||||
|
||||
// ReadFileAbsFunc is a function that reads the full contents from a file in our
|
||||
@@ -46,6 +51,12 @@ type ReadFileAbsFunc 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 *ReadFileAbsFunc) String() string {
|
||||
return ReadFileAbsFuncName
|
||||
}
|
||||
|
||||
// SetData is used by the language to pass our function some code-level context.
|
||||
func (obj *ReadFileAbsFunc) SetData(data *interfaces.FuncData) {
|
||||
obj.data = data
|
||||
|
||||
Reference in New Issue
Block a user