CLI tool
gookit/goutil avatar
gookit/goutil

gookit/goutil: A 900-Function Go Utility Belt with a Few Sharp Edges

Project brief: Helper Utils(900+): int, byte, string, array/slice, map, struct, dump, convert/format, error, web/http, cli/flag, OS/ENV, filesystem, system, test/assert, time and more. Go Map .

2,358 stars201 forksGoMIT

At a glance

What is it?
gookit/goutil bundles over 900 helper functions for Go, from string and slice conversions to CLI and HTTP tools. It is convenient, but its breadth means you must check the source or docs before trusting a function's exact behavior.
Who is it for?
Adopt gookit/goutil if you want a single import for common Go helpers and accept a wide API surface where each function's exact semantics may need checking. Skip it if you prefer minimal dependencies or need strict performance guarantees; the generics-based functions add compile-time overhead but runtime behavior is standard.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 1 day ago.
What is it written in?
Mainly Go, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

What Problem Does goutil Solve?

Go's standard library is deliberately small. Writing a CLI tool or a web service often means repeating the same code: checking if a slice contains a value, converting a string to an int, formatting a struct for debugging. goutil aims to remove that repetition by providing a single package with over 900 functions. The README lists packages for arrays, bytes, maps, math, reflection, structs, strings, system, CLI, environment, filesystem, and JSON. It is for developers who want a Swiss Army knife rather than assembling their own toolkit from multiple smaller libraries. The project also includes testing helpers like assert and fakeobj, which can reduce boilerplate in test files.

The Architecture: Many Sub-Packages, One Entry Point

goutil is not a monolithic package. The repository is organized into sub-packages such as arrutil, strutil, fsutil, and cliutil. Each sub-package has its own focus. The root goutil package re-exports common functions, so you can call goutil.IsEmpty or goutil.Contains without importing sub-packages. The README shows examples like goutil.String(23) returning "23" and goutil.Int("-2") returning 2. Note that the comment says Int("-2") returns 2, which appears to be a typo; the code likely returns -2. This reflects a broader issue: the documentation is sometimes imprecise, so you should verify behavior from source. Internally, many functions use Go generics, as seen in arrutil functions like SliceHas[T comdef.ScalarType] and ContainsAll[T comdef.ScalarType]. This means type safety is enforced at compile time, but it also means the package requires Go 1.18 or later.

Getting Started: Installation and Basic Usage

Installation is a single command: go get github.com/gookit/goutil. The README shows usage examples for basic checks and conversions. For instance, is.True(goutil.IsEmpty(nil)) and is.True(goutil.Contains(map[int]string{2: "abc", 4: "def"}, 4)). The dump package is used for printing variables: dump.Print(somevar, somevar2, ...). The README mentions that dump auto-wraps each element and displays the call location, which is useful for debugging. For sub-packages, you import them directly, such as github.com/gookit/goutil/arrutil for slice functions. The cflag package wraps the standard flag.FlagSet to build CLI apps. There is no separate configuration file; you just import and call functions.

Diving into Specific Packages: arrutil, byteutil, and timex

The arrutil package offers functions like IntsHas, StringsHas, and ToInt64s for converting between types. The byteutil package provides Md5, Random, and Cut functions for byte manipulation. The timex package extends time.Time with methods like DayStart() and DateFormat(), and supports datetime format parsing like "Y-m-d H:i:s", which is different from Go's reference time layout. This can be a relief for developers coming from PHP or Python. However, the breadth means you may not remember all functions exist. The README lists function signatures in collapsible sections, but they are truncated in the material. You will likely need to consult the Go doc for the full list.

Limitations: Error Handling and Documentation Gaps

A significant limitation is error handling in conversion functions. The README shows goutil.Int("-2") returning a value without an error. This implies that conversion functions may silently ignore errors or return zero values on failure. For example, goutil.Int("abc") might return 0 with no error, which can hide bugs. The arrutil.ToInt64s function does return an error, as shown in the example, but the root goutil.Int does not. This inconsistency is a trap. Another limitation is the documentation quality. The README contains a typo in the Int example, and the function lists are truncated. You cannot rely on the README alone; you must read the source or run tests. The project also has many sub-packages, which can increase binary size if you import the root package, though Go's linker may prune unused code.

Alternatives: What Else Is Out There?

The most direct alternative is the standard library plus a few small packages. For string manipulation, strings and strconv cover most needs. For slices, there is no built-in Contains, but you can write a loop or use golang.org/x/exp/slices, which provides a generic Contains function. For struct dumping, spew is a popular library that prints complex structures with indentation and pointer tracking. For CLI apps, spf13/cobra is a full-featured framework, while goutil's cflag is a lighter wrapper around flag. The difference in approach is that goutil tries to be a one-stop shop, whereas alternatives focus on one problem and often have more rigorous APIs. For example, cobra has a well-defined command structure, while cflag just extends FlagSet with helpers.

Maintenance and Licensing

The project is actively maintained, with releases v0.7.5, v0.7.6, and v0.8.0 pushed in May and June 2026. The MIT license is permissive, allowing commercial use with attribution. The repository is not archived. However, the API is still in the 0.x range, meaning breaking changes can occur between minor versions. You should pin a specific version in your go.mod. The README mentions a wiki on ZRead.ai, but the material does not detail upgrade guides or migration notes. Given the large number of functions, the maintenance cost for users is mostly in keeping up with API changes and verifying that a function's behavior matches your expectations after an upgrade.

Final Verdict: Who Should Use It?

goutil is a good fit for small to medium projects where you want to avoid writing boilerplate. It is especially useful for scripts, CLI tools, and internal utilities where you do not need a heavy framework. It is less suitable for large codebases that demand strict error handling or where dependency size is a concern. If you choose to use it, start with the root package for basic functions, and only import sub-packages as needed. Before relying on a function, read its source code or write a quick test to confirm its behavior, especially for conversions. The project's breadth is both its strength and its weakness; you get many helpers, but you must be careful about which ones you trust.

Editorial conclusion

Adopt gookit/goutil if you want a single import for common Go helpers and accept a wide API surface where each function's exact semantics may need checking. Skip it if you prefer minimal dependencies or need strict performance guarantees; the generics-based functions add compile-time overhead but runtime behavior is standard. Before use, verify the specific functions you need against the source, especially conversion functions like Int() that may silently ignore errors, and check the LICENSE for MIT compliance.

Official sources

  1. Official documentation
  2. Official README
  3. Project repository
  4. Release notes
Community notes

Community notes