We're excited to announce the release of gookit/goutil v0.7.2! This version brings numerous new features, optimizations, and bug fixes, further enhancing the stability and usability of this Go utility library.
This update covers multiple modules, including math utilities, string processing, filesystem operations, and command-line flag handling, aiming to provide developers with a richer and more efficient toolkit.
- Project Homepage: https://github.com/gookit/goutil
- Full Changelog: v0.7.2 Release Notes
- Full documentation: https://zread.ai/gookit/goutil
🛠️ Key Bug Fixes
This version fixes several key issues to ensure the stable operation of the library:
- ccolor module: Fixed the issue where the
NO_COLORenvironment variable was not working correctly during printing, improving the compatibility of color output. - cflag module:
- Fixed a
cappruntime error that occurred when parsing global flags. - Fixed the issue where the
OnAppFlagParsedevent was not triggered when no command was input, ensuring the integrity of the event handling logic.
- Fixed a
✨ New Feature Highlights
Math Utilities
- Added the
IsIntegerfunction for strictly checking if a value is of an integer type (e.g.,int(x),uint(x)). - Added
StrictIntandStrictUintconversion functions for stricter integer type conversions. - Added the
FormatBytesfunction to format byte sizes into human-readable strings (e.g., "1.2 MB"), convenient for log output and UI display.
String Utilities
- Added the
NumVersionfunction to quickly extract the numeric part from a version string. - Added the
ReplaceVarsfunction to support quick rendering of strings containing{var}placeholders, simplifying template replacement operations. - Added
IsUpperandIsLowerfunctions to check if a string is entirely uppercase or lowercase. - Added
IsUintandIsPositiveNumfunctions to enhance string numeric validation capabilities. - Added
BaseConvIntandBaseConvIntByTplfunctions to support integer conversion between different bases. - Added the
ContainsByteOnefunction to check if a string contains any of the specified bytes. - Optimized the
MTimeBaseIDfunction, which now supports bases greater than 36.
Filesystem Utilities
- Added the
EnsureDirfunction to ensure a directory exists (creates it if it doesn't). - Added
HomeDir/UserHomeDirfunctions to get the user's home directory path. - Added
CreateSymlinkandIsSymlinkfunctions to support the creation and detection of symbolic links. - Added
FindAllInParentDirs,FindOneInParentDirs, andFindNameInParentDirsfunctions to support finding files in parent directories, simplifying the location of project configuration files.
Array/Slice Utilities
- Added the
ToMapfunction to convert a list (slice) to a map. - Added the
Map1function to convert a list to a new list (similar to a map operation).
Map Utilities
- Added the
AppendSMapfunction for merging string maps. - Added the
AliasesNamesfunction for handling alias names.
Testing Utilities
- Added the
assert.StrContainsAllassertion function to check if a string contains all specified substrings. - Added the
testutil.SafeBuffertype, a thread-safe buffer designed for concurrent testing scenarios. - Enhanced
testutil.EchoServer, which now supports responding with 404, 405, 500, or custom status codes, facilitating the testing of HTTP client error handling logic.
Command-line Utilities
- The
cflagmodule has a newHelpOnEmptyArgsconfiguration option to automatically display help information when no arguments are provided, improving user experience. - Optimized the rendering of help information.
- Added support for setting aliases for
cflag/cappcommands.
Time Utilities
- Added the
FormatDurationfunction to format time duration into a clock-like format (e.g., "1h 23m 45s"), perfect for displaying performance statistics.
⚡ Performance Optimizations & Refactoring
- Optimized the common logic of the
ToStringWithfunction to improve conversion performance. - Refactored
cflag.Appinto the subpackagecapp.App, improving code organization. - Optimized the handling options logic in the
ToInt64Withfunction to enhance conversion efficiency. - Split integer conversion related code into
conv2int.goand optimized the performance of all integer conversion related methods inmathutil. - Updated the
VersionComparefunction logic, fixing some comparison errors and improving the accuracy of version comparison. - The
VarReplacerintextutilnow supports parsing variable names as environment variables, enhancing dynamic configuration capabilities.
🌐 Platform Compatibility & Development Workflow
- Added support for FreeBSD/Unix systems, expanding the platform coverage of the
sysutilpackage. - Added comprehensive GitHub Copilot instructions for gookit/goutil, optimizing the AI-assisted development workflow.
- Upgraded the
github/codeql-actiondependency from version 3 to 4, enhancing the security and capabilities of code analysis.
📝 Other Updates
- Added a
ShowLenoption fordumpoutput, allowing control over whether to display length information. - Updated the README generation CLI and related documentation, improving the project documentation generation process and templates.
- Fixed unit test errors and unified the code style.
- Updated some comments and code styles.
📦 How to Update
You can use the following command to get the latest version:
go get github.com/gookit/goutil@v0.7.2
Migration & Compatibility Notes
-
cflag -> cflag/cappSubpackage Refactoring:cflag.Apphas been refactored tocapp.App. If your code directly referencescflag.App, please adjust:- Old:
import "github.com/gookit/goutil/cflag" - New:
import "github.com/gookit/goutil/capp" - And switch related types/calls to the App in the
capppackage.
- Old:
TIP: This is a potential breaking change in this release, please check and update your references before upgrading.
-
VersionCompareand some string/version-related logic have been optimized. If you rely on the edge-case behavior of the old logic (such as equality comparison or sorting), please run relevant unit tests to verify after upgrading.
Example Snippets
Using mathutil.IsInteger / StrictInt
import "github.com/gookit/goutil/mathutil"
import "github.com/gookit/goutil/testutil/assert"
val := 123
if mathutil.IsInteger(val) {
// true
}
i64, ok := mathutil.StrictInt("42") // Does not allow string to integer conversion
assert.False(t, ok)
Using strutil.ReplaceVars
import "github.com/gookit/goutil/strutil"
tpl := "Hello, {name}! Today is {day}."
out := strutil.ReplaceVars(tpl, map[string]string{
"name": "Gopher",
"day": "Wednesday",
})
// Output: "Hello, Gopher! Today is Wednesday."
Using fsutil.EnsureDir
import "github.com/gookit/goutil/fsutil"
if err := fsutil.EnsureDir("/tmp/myapp/logs"); err != nil {
// Handle error
}
🤝 Contributing
We thank all contributors for their efforts in this release! If you find any issues or have feature suggestions, please feel free to open an issue at GitHub Issues.
📖 More Information
- Project Homepage: https://github.com/gookit/goutil
- Full Changelog: v0.7.2 Release Notes
- Full documentation: https://zread.ai/gookit/goutil
Enjoy the new features and improvements in v0.7.2
Top comments (0)