{"id":51405964,"url":"https://github.com/Goldziher/go-utils","last_synced_at":"2026-07-09T17:00:43.949Z","repository":{"id":40573623,"uuid":"474384687","full_name":"Goldziher/go-utils","owner":"Goldziher","description":"Simple and performant utilies using Go generics inspired by JavaScript and Python","archived":false,"fork":false,"pushed_at":"2026-04-24T11:17:39.000Z","size":10372,"stargazers_count":56,"open_issues_count":0,"forks_count":16,"subscribers_count":4,"default_branch":"main","last_synced_at":"2026-04-24T13:27:07.188Z","etag":null,"topics":["generics","go","golang","utilities"],"latest_commit_sha":null,"homepage":"https://goldziher.github.io/go-utils/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Goldziher.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-03-26T15:17:15.000Z","updated_at":"2026-04-24T11:17:42.000Z","dependencies_parsed_at":"2024-01-09T19:39:00.899Z","dependency_job_id":"444e38ac-ffd3-4dfd-b93b-9eb0a32e3d39","html_url":"https://github.com/Goldziher/go-utils","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/Goldziher/go-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Goldziher%2Fgo-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Goldziher%2Fgo-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Goldziher%2Fgo-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Goldziher%2Fgo-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Goldziher","download_url":"https://codeload.github.com/Goldziher/go-utils/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Goldziher%2Fgo-utils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35306717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-09T02:00:07.329Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["generics","go","golang","utilities"],"created_at":"2026-07-04T11:00:24.070Z","updated_at":"2026-07-09T17:00:43.943Z","avatar_url":"https://github.com/Goldziher.png","language":"Go","funding_links":[],"categories":["Utilities"],"sub_categories":["Utility/Miscellaneous"],"readme":"# Go Utils\n\n\u003cdiv align=\"center\"\u003e\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/Goldziher/go-utils)](https://goreportcard.com/report/github.com/Goldziher/go-utils)\n[![Go Reference](https://pkg.go.dev/badge/github.com/Goldziher/go-utils.svg)](https://pkg.go.dev/github.com/Goldziher/go-utils)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\n\u003c/div\u003e\n\nFunctional programming utilities for **Go 1.21+** designed to complement stdlib's `slices`, `maps`, and `cmp` packages.\n\n## Why Go Utils?\n\n**Complementary to stdlib**: Use `slices.Index`, `slices.Contains`, `slices.Clone` for basic operations. Use go-utils for functional patterns (Map, Filter, Reduce), LINQ-style operations (GroupBy, Partition), and utilities not in stdlib.\n\n**Type-safe with generics**: All functions use Go 1.21+ generics with appropriate constraints for compile-time type safety.\n\n**Immutable by default**: Functions don't mutate inputs. Operations return new values.\n\n**100% test coverage**: Every function is comprehensively tested.\n\n## Installation\n\n```bash\ngo get -u github.com/Goldziher/go-utils\n```\n\n## Quick Examples\n\n### Functional Slice Operations\n\n```go\nimport \"github.com/Goldziher/go-utils/sliceutils\"\n\nnumbers := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}\n\n// Chain functional operations\nevens := sliceutils.Filter(numbers, func(v, i int, s []int) bool {\n    return v%2 == 0\n})\n\ndoubled := sliceutils.Map(evens, func(v, i int, s []int) int {\n    return v * 2\n})\n\nsum := sliceutils.Reduce(doubled, func(acc, v, i int, s []int) int {\n    return acc + v\n}, 0)\n// Result: sum = 60 (2+4+6+8+10 doubled = 4+8+12+16+20 = 60)\n```\n\n### LINQ-Style Operations\n\n```go\ntype User struct {\n    Name string\n    Age  int\n    Role string\n}\n\nusers := []User{\n    {\"Alice\", 30, \"admin\"},\n    {\"Bob\", 25, \"user\"},\n    {\"Charlie\", 30, \"user\"},\n}\n\n// Group by age\nbyAge := sliceutils.GroupBy(users, func(u User) int { return u.Age })\n// Result: map[int][]User{25: [{Bob 25 user}], 30: [{Alice 30 admin}, {Charlie 30 user}]}\n\n// Partition by predicate\nadmins, regularUsers := sliceutils.Partition(users, func(u User) bool {\n    return u.Role == \"admin\"\n})\n\n// Get distinct ages\nages := sliceutils.DistinctBy(users, func(u User) int { return u.Age })\n```\n\n### Map Transformations\n\n```go\nimport \"github.com/Goldziher/go-utils/maputils\"\n\ndata := map[string]int{\"apple\": 5, \"banana\": 3, \"cherry\": 8}\n\n// Extract keys and values\nkeys := maputils.Keys(data)     // []string{\"apple\", \"banana\", \"cherry\"}\nvalues := maputils.Values(data) // []int{5, 3, 8}\n\n// Filter map entries\nfiltered := maputils.Filter(data, func(k string, v int) bool {\n    return v \u003e 4\n})\n// Result: map[string]int{\"apple\": 5, \"cherry\": 8}\n```\n\n### Type-Safe String Conversion\n\n```go\nimport \"github.com/Goldziher/go-utils/stringutils\"\n\n// Stringify any type with options\nhex := stringutils.Stringify(42, stringutils.Options{Base: 16})  // \"2a\"\nfloat := stringutils.Stringify(3.14159, stringutils.Options{Precision: 2})  // \"3.14\"\n\n// Stringify complex types\nm := map[string]int{\"a\": 1, \"b\": 2}\nstr := stringutils.Stringify(m)  // \"{a: 1, b: 2}\"\n```\n\n### Business Date Calculations\n\n```go\nimport \"github.com/Goldziher/go-utils/dateutils\"\n\n// Add business days (skips weekends)\nfuture := dateutils.AddBusinessDays(time.Now(), 5)\n\n// Check date range overlap\noverlaps := dateutils.Overlap(start1, end1, start2, end2)\n\n// Calculate age\nage := dateutils.Age(birthdate)\n```\n\n## Packages\n\n| Package | Description | Key Functions |\n|---------|-------------|---------------|\n| **[sliceutils](https://pkg.go.dev/github.com/Goldziher/go-utils/sliceutils)** | Functional and LINQ-style slice operations | Map, Filter, Reduce, GroupBy, Partition, Find |\n| **[maputils](https://pkg.go.dev/github.com/Goldziher/go-utils/maputils)** | Map transformations | Keys, Values, Filter, Merge, Invert |\n| **[stringutils](https://pkg.go.dev/github.com/Goldziher/go-utils/stringutils)** | String manipulation | Stringify, ToCamelCase, ToSnakeCase, Truncate |\n| **[structutils](https://pkg.go.dev/github.com/Goldziher/go-utils/structutils)** | Struct reflection utilities | ToMap, ForEach, FieldNames (tag-aware) |\n| **[dateutils](https://pkg.go.dev/github.com/Goldziher/go-utils/dateutils)** | Date/time utilities | AddBusinessDays, Overlap, Age, StartOfWeek |\n| **[urlutils](https://pkg.go.dev/github.com/Goldziher/go-utils/urlutils)** | URL and query string builders | QueryStringifyMap, QueryStringifyStruct |\n| **[mathutils](https://pkg.go.dev/github.com/Goldziher/go-utils/mathutils)** | Generic math operations | Clamp, InRange, Gcd, Lcm, IsPrime |\n| **[ptrutils](https://pkg.go.dev/github.com/Goldziher/go-utils/ptrutils)** | Pointer utilities | ToPtr, Deref |\n| **[excutils](https://pkg.go.dev/github.com/Goldziher/go-utils/excutils)** | Exception-style error handling | Panic, Try, Must |\n\n## Documentation\n\nFull documentation available at [goldziher.github.io/go-utils](https://goldziher.github.io/go-utils/)\n\nAPI reference at [pkg.go.dev/github.com/Goldziher/go-utils](https://pkg.go.dev/github.com/Goldziher/go-utils)\n\n## Contributing\n\nContributions are welcome! Please read the [Contributing Guide](CONTRIBUTING.md) before submitting PRs.\n\n## License\n\nMIT License - see [LICENSE](LICENSE) for details.\n\n## Author\n\n[Na'aman Hirschfeld](https://github.com/Goldziher)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoldziher%2Fgo-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGoldziher%2Fgo-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoldziher%2Fgo-utils/lists"}