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

@@ -26,11 +26,15 @@ import (
)
const (
// LoadFuncName 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.
LoadFuncName = "load"
loadSignature = "struct{x1 float; x5 float; x15 float}"
)
func init() {
facts.ModuleRegister(ModuleName, "load", func() facts.Fact { return &LoadFact{} }) // must register the fact and name
facts.ModuleRegister(ModuleName, LoadFuncName, func() facts.Fact { return &LoadFact{} }) // must register the fact and name
}
// LoadFact is a fact which returns the current system load.
@@ -39,6 +43,12 @@ type LoadFact 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 *LoadFact) String() string {
return LoadFuncName
}
// Validate makes sure we've built our struct properly. It is usually unused for
// normal facts that users can use directly.
//func (obj *LoadFact) Validate() error {