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:
James Shubin
2023-03-03 14:12:09 -05:00
parent 8366cf0873
commit 5d664855de
35 changed files with 365 additions and 39 deletions

View File

@@ -35,8 +35,13 @@ import (
"github.com/purpleidea/mgmt/util/errwrap"
)
const (
// VUMeterFuncName is the name this function is registered as.
VUMeterFuncName = "vumeter"
)
func init() {
funcs.ModuleRegister(ModuleName, "vumeter", func() interfaces.Func { return &VUMeterFunc{} }) // must register the func and name
funcs.ModuleRegister(ModuleName, VUMeterFuncName, func() interfaces.Func { return &VUMeterFunc{} }) // must register the func and name
}
// VUMeterFunc is a gimmic function to display a vu meter from the microphone.
@@ -53,6 +58,12 @@ type VUMeterFunc 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 *VUMeterFunc) String() string {
return VUMeterFuncName
}
// ArgGen returns the Nth arg name for this function.
func (obj *VUMeterFunc) ArgGen(index int) (string, error) {
seq := []string{"symbol", "multiplier", "peak"}