-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate all functions under function handler 🌱✨ (#14)
## Description This pull request represents a significant milestone in our ongoing project to migrate all functionalities from `sprig` to the new `sprout` function handler. This transition allows for a phased approach, setting the stage for subsequent enhancements. ## Changes - Refactored all functions to be methods of the `FunctionHandler` struct. - Improved test coverage to ensure all functions perform as expected. - Categorized functions into appropriate groups: `misc`, `urls`, `semver`, `maps`, `slices`, `regexp`, `conversion`, `network`, `crypto`, `time`, `filesystem`, `encoding`, `numeric`, `strings`, and `random`. ## Fixes #13 #15 #16 #17 #18 #19 #20 #21 #22 #23 #24 #25 #26 ## Checklist - [x] I have read the **CONTRIBUTING.md** document. - [x] My code follows the code style of this project. (This pull request define it ) - [x] I have added tests to cover my changes. - [x] All new and existing tests passed. - [ ] I have updated the documentation accordingly. - [x] This change requires a change to the documentation on the website. ## Additional Information This pull request consolidates all necessary migration tasks into a single update due to the complexity and interdependencies of the changes involved. This strategic choice accelerates our transition without compromising the integrity of our functionalities.
- Loading branch information
Showing
71 changed files
with
8,118 additions
and
5,064 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Migration Notes for Sprout Library | ||
This document outlines the key differences and migration changes between the | ||
Sprig and Sprout libraries. The changes are designed to enhance stability and | ||
usability in the Sprout library. | ||
|
||
This document will help contributors and maintainers understand the changes made | ||
between the fork date and version 1.0.0 of the Sprout library. | ||
|
||
It will be updated to reflect changes in future versions of the library. | ||
|
||
This document will also assist in creating the migration guide when version 1.0 is ready. | ||
|
||
|
||
## Error Handling Enhancements | ||
### General Error Handling | ||
In Sprig, errors within certain functions cause a panic. | ||
In contrast, Sprout opts for returning nil or an empty value, improving safety | ||
and predictability. | ||
|
||
**Old Behavior (Sprig)**: Triggers a panic on error | ||
```go | ||
if err != nil { | ||
panic("deepCopy error: " + err.Error()) | ||
} | ||
``` | ||
|
||
**New Behavior (Sprout)**: Returns nil or an empty value on error | ||
```go | ||
if err != nil { | ||
return nil, err | ||
} | ||
``` | ||
|
||
Methods that previously caused a panic in Sprig : | ||
- DeepCopy | ||
- MustDeepCopy | ||
- ToRawJson | ||
- Append | ||
- Prepend | ||
- Concat | ||
- Chunk | ||
- Uniq | ||
- Compact | ||
- Slice | ||
- Without | ||
- Rest | ||
- Initial | ||
- Reverse | ||
- First | ||
- Last | ||
- Has | ||
- Dig | ||
- RandAlphaNumeric | ||
- RandAlpha | ||
- RandAscii | ||
- RandNumeric | ||
- RandBytes | ||
|
||
## Function-Specific Changes | ||
|
||
### MustDeepCopy | ||
|
||
- **Sprig**: Accepts `nil` input, causing an internal panic. | ||
- **Sprout**: Returns `nil` if input is `nil`, avoiding panic. | ||
|
||
## Rand Functions | ||
|
||
- **Sprig**: Causes an internal panic if the length parameter is zero. | ||
- **Sprout**: Returns an empty string if the length is zero, ensuring stability. | ||
|
||
## DateAgo | ||
|
||
- **Sprig**: Does not support int32 and *time.Time; returns "0s". | ||
- **Sprout**: Supports int32 and *time.Time and returns the correct duration. | ||
|
||
## DateRound | ||
- **Sprig**: Returns a corrected duration in positive form, even for negative inputs. | ||
- **Sprout**: Accurately returns the duration, preserving the sign of the input. | ||
|
||
## Base32Decode / Base64Decode | ||
- **Sprig**: Decoding functions return the error string when the input is not a valid base64 encoded string. | ||
- **Sprout**: Decoding functions return an empty string if the input is not a valid base64 encoded string, simplifying error handling. | ||
|
||
## Dig | ||
> Consider the example dictionary defined as follows: | ||
> ```go | ||
> dict := map[string]any{ | ||
> "a": map[string]any{ | ||
> "b": 2, | ||
> }, | ||
> } | ||
> ``` | ||
- **Sprig**: Previously, the `dig` function would return the last map in the access chain. | ||
```go | ||
{{ $dict | dig "a" "b" }} // Output: map[b:2] | ||
``` | ||
- **Sprout**: Now, the `dig` function returns the final object in the chain, regardless of its type (map, array, string, etc.). | ||
```go | ||
{{ $dict | dig "a" "b" }} // Output: 2 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.