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,8 +25,14 @@ import (
|
||||
"github.com/purpleidea/mgmt/util/errwrap"
|
||||
)
|
||||
|
||||
const (
|
||||
// UptimeFuncName is the name this fact is registered as. It's still a
|
||||
// Func Name because this is the name space the fact is actually using.
|
||||
UptimeFuncName = "uptime"
|
||||
)
|
||||
|
||||
func init() {
|
||||
facts.ModuleRegister(ModuleName, "uptime", func() facts.Fact { return &UptimeFact{} })
|
||||
facts.ModuleRegister(ModuleName, UptimeFuncName, func() facts.Fact { return &UptimeFact{} })
|
||||
}
|
||||
|
||||
// UptimeFact is a fact which returns the current uptime of your system.
|
||||
@@ -35,6 +41,12 @@ type UptimeFact struct {
|
||||
closeChan chan struct{}
|
||||
}
|
||||
|
||||
// String returns a simple name for this fact. This is needed so this struct can
|
||||
// satisfy the pgraph.Vertex interface.
|
||||
func (obj *UptimeFact) String() string {
|
||||
return UptimeFuncName
|
||||
}
|
||||
|
||||
// Info returns some static info about itself.
|
||||
func (obj *UptimeFact) Info() *facts.Info {
|
||||
return &facts.Info{
|
||||
|
||||
Reference in New Issue
Block a user