8000 docs: fix registry code example by sagikazarmark · Pull Request #126 · go-sprout/sprout · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

docs: fix registry code example #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/advanced/how-to-create-a-registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ func (or *OwnRegistry) LinkHandler(fh sprout.Handler) error {

// 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) {
func (or *OwnRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error {
// Example of registering a function
sprout.AddFunction(funcsMap, "yourFunction", or.YourFunction)

return nil
}

// OPTIONAL: Your registry don't needs to register aliases to work.
Expand All @@ -66,6 +68,8 @@ func (or *OwnRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) {
func (or *OwnRegistry) RegisterAliases(aliasMap sprout.FunctionAliasMap) error {
// Example of registering an alias
sprout.AddAlias(aliasMap, "yourFunction", "yourAlias")

return nil
}
```

Expand All @@ -82,4 +86,4 @@ func (or *OwnRegistry) YourFunction() (string, error) {
**Important:** Make sure to write tests for your functions in `functions_test.go` to validate their functionality.
{% endhint %}

Once your registry is defined and functions are implemented, you can start using it in your projects. 🎉
Once your registry is defined and functions are implemented, you can start using it in your projects. 🎉
Loading
0