Releases: yoockh/go-api-utils
v0.2.8 - downgrade Go version from 1.25.1 to 1.24.0 in go.mod
v0.2.7 - First Steps with Yoockh
- Updated module paths to reflect new GitHub username yoockh
- Added Echo package for routing utilities
- Minor fixes and code cleanup
v0.2.6 — Echo: JWT & helpers, pagination, health, docs
Patch release that adds Echo helpers, tightens JWT middleware, introduces pagination & health endpoints, and improves docs.
Summary
- Add Echo request helpers: BindAndRequireFields, RequireFields (BindAndValidate deprecated).
- Add request helpers: QueryString, QueryInt, PathParamUint, token data GetUint/GetInt/GetString.
- Add response helpers: SuccessData (raw), Paginated (with meta).
- Improve JWT middleware: robust Authorization parsing, explicit "token expired" handling, map jwt.ErrTokenExpired -> ErrExpiredToken.
- Add middleware: RequireRoles and context getters CurrentUserID/Email/Role.
- Add ORM pagination helpers: ApplyPagination, CountAndPaginate; WithTransaction now uses db.Transaction.
- Add health endpoint: health.NewHandler(db).
- Validator: ValidateRequired trims whitespace.
- Auth: bcrypt cost override via BCRYPT_COST.
- Docs: README updated with examples, function reference, and changelog.
Upgrade notes
- BindAndValidate is deprecated. Replace with BindAndRequireFields(c, &req, "field1", ...).
- Middleware sets token data under context keys: "token_data", "user_id", "email", "role" (use helpers to read).
- If you rely on jwt parsing errors, use auth.ErrExpiredToken to detect expiration specially.
Quick install
go get github.com/Yoochan45/go-api-utils@v0.2.5Publish via GitHub CLI (example)
gh release create v0.2.5 \
--title "v0.2.5 — Echo: JWT & helpers, pagination, health, docs" \
--notes-file ./RELEASE_NOTES_v0.2.5.md(Optionally paste the Release description above into GitHub's "Release notes" box.)
v0.2.0 - Echo Framework Support + JWT Authentication
What's New
Echo Framework Support
Added complete Echo framework integration with the following packages:
pkg-echo/auth- JWT token generation/validation & password hashing (bcrypt)pkg-echo/middleware- JWT authentication middleware for Echopkg-echo/response- Standardized JSON response helpers for Echopkg-echo/validator- Input validation utilities (email, required fields, min length)pkg-echo/orm- GORM connection helpers & transaction wrapperpkg-echo/request- Request binding & validation helpers
New Features
- JWT Authentication (using
github.com/golang-jwt/jwt/v5) - Password hashing with bcrypt
- GORM ORM support for PostgreSQL
- Database transaction wrapper
- Request validation helpers
- Echo-specific response helpers
Examples
- Added
examples/04-echo-jwt-api- Complete JWT authentication example with Echo + GORM
Improvements
- Updated
pkg/databaseto support SKIP_DB environment variable - Added
database.Init()for simplified database initialization - Improved README with Echo framework documentation and usage examples
- Added context.Context support in all database queries
Installation
go get github.com/Yoochan45/go-api-utils@v0.2.0Quick Start (Echo + JWT)
package main
import (
"github.com/Yoochan45/go-api-utils/pkg/config"
"github.com/Yoochan45/go-api-utils/pkg-echo/auth"
"github.com/Yoochan45/go-api-utils/pkg-echo/middleware"
"github.com/Yoochan45/go-api-utils/pkg-echo/response"
"github.com/labstack/echo/v4"
)
func main() {
cfg := config.LoadEnv()
e := echo.New()
// Public routes
e.POST("/login", handleLogin)
// Protected routes
api := e.Group("/api")
api.Use(middleware.JWTMiddleware(middleware.JWTConfig{
SecretKey: "your-secret",
}))
api.GET("/profile", handleProfile)
e.Start(":" + cfg.Port)
}Documentation
Full documentation available in README.md
Migration from v0.1.0
No breaking changes! All existing pkg/* packages remain unchanged and fully compatible.
New Echo packages are in separate pkg-echo/* directory.
Bug Fixes
- Fixed database connection hanging on IPv6 networks
- Added proper error handling for database.Init()
Dependencies
New dependencies:
github.com/labstack/echo/v4- Echo web frameworkgithub.com/golang-jwt/jwt/v5- JWT implementationgolang.org/x/crypto- Bcrypt password hashinggorm.io/gorm- GORM ORMgorm.io/driver/postgres- PostgreSQL driver for GORM
Developer
Aisiya Qutwatunnada (@Yoochan45)
Full Changelog: v0.1.0...v0.2.0
Initial Release - v0.1.0
Initial Release of Go API Utils (v0.1.0)
Go API Utils adalah library ringan untuk mempercepat pengembangan REST API menggunakan Go. Package ini dibuat untuk menghindari penulisan ulang kode dasar seperti koneksi database, response JSON, middleware, dan helper CRUD.
Fitur Utama
- Database Utilities (PostgreSQL)
- ConnectPostgresURL() menggunakan DATABASE_URL (Supabase, Railway, Render)
- ConnectPostgres() menggunakan konfigurasi manual
- MustConnect() untuk otomatis panic jika gagal
- Close() untuk menutup koneksi database
- JSON Response Helper
- Success(), Created(), NoContent()
- BadRequest(), NotFound(), InternalServerError()
- Request Utilities
- ParseJSON() untuk membaca body JSON
- GetIDFromURL() untuk mengambil parameter ID dari URL
- GetQueryParam() dan GetQueryParamInt() untuk query string
- CRUD Query Builder
- BuildInsertQuery()
- BuildUpdateQuery()
- BuildSelectQuery()
- CheckRowsAffected()
- Middleware
- CORS() untuk menangani Cross-Origin Resource Sharing
- Logger() untuk logging HTTP request
- Environment Config Loader
- LoadEnv() dan MustLoadEnv() untuk membaca file .env
Examples
Tersedia contoh penggunaan:
- Basic API (tanpa database)
- Koneksi database PostgreSQL
- Full CRUD API
Cara menjalankan:
cd examples/01-basic-api && go run main.go
cd examples/02-database-connection && go run main.go
cd examples/03-crud-api && go run main.go
Catatan
- Versi ini adalah rilis awal (v0.1.0)
- Masih terbuka