go-utils

module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2025 License: MIT

README

Go Utils

Go Go Report Card GoDoc

A collection of Go utility functions I've been building up over time. Started with just string utils for a work project, but it's grown into a decent little toolkit.

What's in here?

Basically a bunch of helper functions that I kept copy-pasting between projects. Decided to just make them into a proper library.

String Stuff (stringutils)
  • Case conversions (camelCase, snake_case, etc.)
  • Basic string manipulation
  • Some validation helpers
Slice Operations (sliceutils)
  • Generic slice functions (filter, map, etc.)
  • Works with Go 1.18+ generics
Other Utils
  • maputils: Map operations
  • jsonutils: JSON helpers (because encoding/json can be verbose)
  • validationutils: Email, password validation
  • timeutils: Date/time helpers
  • fileutils: File I/O shortcuts
  • httputils: HTTP utilities
  • cryptoutils: Crypto functions (secure ones only)
  • mathutils: Mathematical functions (basic & optimized advanced operations)
  • errorutils: Better error handling
  • configutils: Config loading from env/files
  • securityutils: Security helpers
  • testutils: Testing utilities

Installation

go get github.com/alexzzzs/go-utils

Quick Examples

package main

import (
    "fmt"
    "github.com/alexzzzs/go-utils/stringutils"
    "github.com/alexzzzs/go-utils/sliceutils"
    "github.com/alexzzzs/go-utils/mathutils"
)

func main() {
    // String case conversion
    text := "hello world"
    camel := stringutils.CamelCase(text) // "helloWorld"
    snake := stringutils.SnakeCase("HelloWorld") // "hello_world"
    
    // Slice operations
    numbers := []int{1, 2, 3, 4, 5}
    evens := sliceutils.Filter(numbers, func(n int) bool { 
        return n%2 == 0 
    })
    fmt.Println(evens) // [2, 4]
    
    // Math operations - basic and optimized
    values := []int{10, 25, 17, 8, 42}
    max, _ := mathutils.MaxSlice(values) // 42
    avg, _ := mathutils.Average(values)  // 20.4
    
    // Fast approximations for games/graphics
    fastSin := mathutils.FastSin(1.57) // ≈ 1.0 (faster than math.Sin)
    invSqrt := mathutils.FastInvSqrt(4.0) // ≈ 0.5 (famous Quake algorithm)
}

Why another utils library?

Honestly, there are probably better ones out there. But I wanted:

  • Zero external dependencies
  • Simple, focused functions
  • Good test coverage
  • No bloat

Plus I was tired of googling "golang string to camelCase" every few weeks.

Testing

go test ./...              # Run all tests
go test -cover ./...       # With coverage
go test -race ./...        # Race condition detection

Most packages have decent test coverage. Some could probably use more edge case testing.

Documentation

See API.md for detailed docs. Or just read the code - it's pretty straightforward.

Also check out CHANGELOG.md if you're into that sort of thing.

Contributing

Feel free to open issues or PRs. I'm not super picky about style as long as:

  • Tests pass
  • No external dependencies
  • Functions are documented

License

MIT - do whatever you want with it.

Directories

Path Synopsis
Package configutils provides utility functions for configuration management and environment variable handling.
Package configutils provides utility functions for configuration management and environment variable handling.
Package cryptoutils provides cryptographic utilities using secure standard library functions.
Package cryptoutils provides cryptographic utilities using secure standard library functions.
Package errorutils provides typed error utilities and error handling helpers.
Package errorutils provides typed error utilities and error handling helpers.
Package main demonstrates the Go utils library.
Package main demonstrates the Go utils library.
Package fileutils provides essential file operation utilities.
Package fileutils provides essential file operation utilities.
Package httputils provides HTTP utilities and helpers.
Package httputils provides HTTP utilities and helpers.
Package jsonutils provides essential JSON utilities.
Package jsonutils provides essential JSON utilities.
Package maputils provides essential map manipulation utilities.
Package maputils provides essential map manipulation utilities.
Package mathutils - because apparently I needed MORE math in my life Contains basic math functions and some black magic optimization algorithms that I probably shouldn't understand but somehow work.
Package mathutils - because apparently I needed MORE math in my life Contains basic math functions and some black magic optimization algorithms that I probably shouldn't understand but somehow work.
Package securityutils provides utility functions for security operations and data sanitization.
Package securityutils provides utility functions for security operations and data sanitization.
Package sliceutils provides slice manipulation utilities.
Package sliceutils provides slice manipulation utilities.
Package stringutils provides string manipulation utilities.
Package stringutils provides string manipulation utilities.
Package testutils provides utility functions for testing and test assertions.
Package testutils provides utility functions for testing and test assertions.
Package timeutils provides essential time utilities.
Package timeutils provides essential time utilities.
Package validationutils provides essential validation utilities.
Package validationutils provides essential validation utilities.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL