README
ΒΆ
Godash
A comprehensive Go utility library providing essential tools for modern Go applications. Godash offers type-safe, performant utilities for common programming tasks with a focus on functional programming patterns and developer experience.
π οΈ Installation
go get github.com/entrylens/godash@latest
π Features
- Type Safe: All utilities use Go generics for compile-time type safety
- Performance Focused: Optimized for Go's performance characteristics
- Comprehensive Testing: Extensive test coverage for all packages
- Modern Go: Built for Go 1.23+ with latest language features
- Production Ready: Used in production environments with robust error handling
π¦ Packages
sliceskit - Functional Slice Utilities
Comprehensive slice manipulation utilities inspired by functional programming patterns.
import "github.com/entrylens/godash/sliceskit"
numbers := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
// Filter even numbers and map to squares
squares := sliceskit.Map(
sliceskit.Filter(numbers, func(n int) bool { return n%2 == 0 }),
func(n int) int { return n * n },
)
// Result: [4, 16, 36, 64, 100]
// Find first number greater than 5
found, exists := sliceskit.Find(numbers, func(n int) bool { return n > 5 })
// Result: 6, true
// Check if any number is even
hasEven := sliceskit.Any(numbers, func(n int) bool { return n%2 == 0 })
// Result: true
Key Functions:
Map,Filter,Reduce- Core functional operationsAny,Every- Predicate checkingFind,FindPtr- Element searchingChunk- Slice partitioning- Error handling variants for robust applications
jsonkit - JSON & Protobuf Utilities
Streamlined JSON and Protocol Buffer handling for HTTP applications.
import "github.com/entrylens/godash/jsonkit"
// HTTP Request/Response handling
type User struct {
Name string `json:"name"`
Age int `json:"age"`
}
// Bind JSON request body to struct
var user User
err := jsonkit.BindRequestBody(r, &user)
// Send JSON response
err = jsonkit.JSONResponse(w, http.StatusOK, user)
// Protobuf support
message := &pb.User{Name: "Alice", Age: 30}
err = jsonkit.ProtoJSONResponse(w, http.StatusOK, message)
Key Features:
- HTTP request/response JSON binding
- Protocol Buffer JSON serialization
- Strict JSON validation (no unknown fields)
- Error handling for malformed JSON
slogkit - Structured Logging Utilities
Context-aware structured logging extensions for Go's log/slog package.
import (
"context"
"log/slog"
"github.com/entrylens/godash/slogkit"
)
handler := slogkit.NewContextHandler(slogkit.ContextHandlerOptions{
UseJson: true,
Level: slog.LevelInfo,
AddSource: true,
AppendAttrFromContext: func(ctx context.Context) ([]slog.Attr, error) {
if requestID, ok := ctx.Value("request_id").(string); ok {
return []slog.Attr{slog.String("request_id", requestID)}, nil
}
return nil, nil
},
})
logger := slog.New(handler)
ctx := context.WithValue(context.Background(), "request_id", "req-123")
logger.InfoContext(ctx, "Processing request")
Key Features:
- Context-aware attribute extraction
- JSON and text output formats
- Source file tracking
- Process ID logging
π Requirements
- Go 1.23 or higher
- For protobuf features:
google.golang.org/protobuf
π§ͺ Testing
Run the full test suite:
make test
Or test specific packages:
go test ./sliceskit/...
go test ./jsonkit/...
go test ./slogkit/...
π§ Development
Prerequisites
- Go 1.23+
- Make (for build automation)
- golangci-lint (for code quality)
Available Commands
make check # Run all checks (format, lint, test)
make fmt # Format code
make lint # Run linter
make test # Run tests
make tidy # Tidy dependencies
make regen_proto # Regenerate protobuf code
Code Quality
The project uses:
- golangci-lint for static analysis
- testify for testing utilities
- Go modules for dependency management
- Git hooks (via lefthook) for pre-commit checks
π Performance
All utilities are designed with performance in mind:
- Zero allocations where possible
- Efficient memory usage
- Optimized for Go's slice operations
- Minimal overhead over standard library
π€ Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Guidelines
- Follow Go best practices and idioms
- Add comprehensive tests for new features
- Update documentation for API changes
- Ensure all tests pass before submitting PR
- Use meaningful commit messages
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- Inspired by functional programming patterns from various languages
- Built on Go's excellent standard library
- Community feedback and contributions
Made with β€οΈ for the Go community
Click to show internal directories.
Click to hide internal directories.