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:
@@ -28,10 +28,15 @@ import (
|
||||
"github.com/purpleidea/mgmt/util/errwrap"
|
||||
)
|
||||
|
||||
const alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
const (
|
||||
// Random1FuncName is the name this function is registered as.
|
||||
Random1FuncName = "random1"
|
||||
|
||||
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
)
|
||||
|
||||
func init() {
|
||||
funcs.Register("random1", func() interfaces.Func { return &Random1Func{} })
|
||||
funcs.Register(Random1FuncName, func() interfaces.Func { return &Random1Func{} })
|
||||
}
|
||||
|
||||
// Random1Func returns one random string of a certain length.
|
||||
@@ -52,6 +57,12 @@ type Random1Func 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 *Random1Func) String() string {
|
||||
return Random1FuncName
|
||||
}
|
||||
|
||||
// ArgGen returns the Nth arg name for this function.
|
||||
func (obj *Random1Func) ArgGen(index int) (string, error) {
|
||||
seq := []string{"length"}
|
||||
|
||||
Reference in New Issue
Block a user