How to create a registry
File Naming Conventions
Creating a Registry
package ownregistry
import (
"github.com/go-sprout/sprout"
)
// OwnRegistry struct implements the Registry interface, embedding the Handler to access shared functionalities.
type OwnRegistry struct {
handler sprout.Handler // Embedding Handler for shared functionality
}
// NewRegistry initializes and returns a new instance of your registry.
func NewRegistry() *OwnRegistry {
return &OwnRegistry{}
}
// Uid provides a unique identifier for your registry.
func (or *OwnRegistry) Uid() string {
return "organization.ownRegistry" // Ensure this identifier is unique and uses camelCase, prefixed by your handler separated with a dot.
}
// LinkHandler connects the Handler to your registry, enabling runtime functionalities.
func (or *OwnRegistry) LinkHandler(fh sprout.Handler) error {
or.handler = fh
return nil
}
// RegisterFunctions adds the provided functions into the given function map.
// This method is called by an Handler to register all functions of a registry.
func (or *OwnRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) {
// Example of registering functions
sprout.AddFunction(funcsMap, "yourFunction", or.YourFunction)
sprout.AddFunction(funcsMap, "oldFunc", or.OldFunc) // example for Notice
sprout.AddFunction(funcsMap, "newFunc", or.NewFunc) // example for Notice
}
// OPTIONAL: Your registry don't needs to register aliases to work.
// RegisterAliases adds the provided aliases into the given alias map.
// method is called by an Handler to register all aliases of a registry.
func (or *OwnRegistry) RegisterAliases(aliasMap sprout.FunctionAliasMap) error {
// Example of registering an alias
sprout.AddAlias(aliasMap, "yourFunction", "yourAlias")
}
// OPTIONAL: Your registry don't needs to register notices to work.
// RegisterNotices add the provided notices into the given list of notices.
// method is called by an Handler to register all notices of a registry.
func (or *OwnRegistry) RegisterNotices(notices *[]sprout.FunctionNotice) error {
// Example of registering a notice on the function oldFunc to indicate
// that the function is now deprecated and will be removed in the next version.
sprout.AddNotice(notices, sprout.NewDeprecatedNotice("oldFunc", "please use `newFunc` instead"))
return nil
}Last updated