go-pkg

A comprehensive Go utility package providing essential tools for web development, including internationalization (i18n), HTTP response handling, custom types, and helper functions.
Features
- i18n: Multi-language support with JSON-based locales and Fiber integration
- Response: Standardized HTTP response utilities with i18n support
- Validator: Struct validation with user-friendly, multilingual error messages
- Security: Password hashing and verification with bcrypt
- Types: Custom time types (UTCTime) for consistent UTC JSON serialization
- Helpers: Utility functions for pointers, JSON handling, string manipulation, and ID generation
- Databases: MySQL and PostgreSQL database utilities with GORM integration
- Logger: Logging utilities with timestamp support
Installation
go get github.com/budimanlai/go-pkg
Quick Start
Basic Usage
import (
"github.com/budimanlai/go-pkg/i18n"
"github.com/budimanlai/go-pkg/response"
"github.com/budimanlai/go-pkg/types"
"github.com/gofiber/fiber/v2"
"golang.org/x/text/language"
)
// Setup i18n
config := i18n.I18nConfig{
DefaultLanguage: language.English,
SupportedLangs: []string{"en", "id"},
LocalesPath: "./locales",
}
i18nManager, _ := i18n.NewI18nManager(config)
// Use in Fiber app
app := fiber.New()
response.SetI18nManager(i18nManager)
app.Get("/", func(c *fiber.Ctx) error {
return response.Success(c, "Welcome!", map[string]string{"version": "1.0"})
})
Custom Time Type
import "github.com/budimanlai/go-pkg/types"
type Event struct {
CreatedAt types.UTCTime `json:"created_at"`
}
event := Event{CreatedAt: types.UTCTime(time.Now())}
// JSON output: {"created_at":"2025-10-15T12:30:45Z"}
Documentation
Comprehensive documentation is available in the docs/ folder:
Main Packages
- databases - MySQL and PostgreSQL database management with GORM
- helpers - JSON utilities, pointer operations, string helpers, ID generation
- i18n - Internationalization with go-i18n and Fiber middleware
- logger - Logging utilities with timestamp support
- security - Password hashing and verification with bcrypt
- types - Custom UTCTime type for timezone-safe JSON handling
Response Package (Multiple Files)
The response package documentation is organized in the docs/response/ folder:
- README - Overview and quick start
- Standard Responses - Basic response functions (Success, Error, NotFound, BadRequest)
- I18n Responses - Internationalized response functions with automatic translation
- Error Handler - Custom Fiber error handler with i18n support
- Examples - Practical examples (REST API, authentication, file upload, pagination)
Validator Package (Multiple Files)
The validator package documentation is organized in the docs/validator/ folder:
- README - Overview and quick start
- Validation Tags - Complete reference for all validation rules (required, email, min, max, etc.)
- Error Handling - ValidationError type, error handling patterns, response formats
- I18n Integration - Multilingual validation messages setup and configuration
- Examples - Practical examples (user registration, complex structs, nested validation)
Testing
Run all tests:
go test ./...
Run tests with coverage:
go test -cover ./...
Generate coverage report:
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
Project Structure
go-pkg/
├── databases/ # Database utilities (MySQL)
├── docs/ # Documentation
├── helpers/ # General utility functions
├── i18n/ # Internationalization
├── locales/ # Translation files
├── response/ # HTTP response helpers
├── security/ # Password hashing utilities
├── types/ # Custom types
├── validator/ # Validation utilities
├── go.mod
├── go.sum
├── LICENSE
└── README.md
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature)
- Commit your changes (
git commit -m 'Add some AmazingFeature')
- Push to the branch (
git push origin feature/AmazingFeature)
- Open a Pull Request
Please ensure all tests pass and add tests for new features.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
If you find this package helpful, please give it a ⭐ on GitHub!
For issues or questions, please open an issue on GitHub.