Skip to content

Releases: yoockh/go-api-utils

v0.2.8 - downgrade Go version from 1.25.1 to 1.24.0 in go.mod

12 Nov 18:56
5d18e4d

Choose a tag to compare

fix: downgrade Go version from 1.25.1 to 1.24.0 in go.mod

v0.2.7 - First Steps with Yoockh

11 Nov 08:23
0f59104

Choose a tag to compare

  • 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

26 Oct 19:32
a41bcdc

Choose a tag to compare

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.5

Publish 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

26 Oct 08:35
8b360d3

Choose a tag to compare

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 Echo
  • pkg-echo/response - Standardized JSON response helpers for Echo
  • pkg-echo/validator - Input validation utilities (email, required fields, min length)
  • pkg-echo/orm - GORM connection helpers & transaction wrapper
  • pkg-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/database to 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.0

Quick 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 framework
  • github.com/golang-jwt/jwt/v5 - JWT implementation
  • golang.org/x/crypto - Bcrypt password hashing
  • gorm.io/gorm - GORM ORM
  • gorm.io/driver/postgres - PostgreSQL driver for GORM

Developer

Aisiya Qutwatunnada (@Yoochan45)


Full Changelog: v0.1.0...v0.2.0

Initial Release - v0.1.0

19 Oct 11:59

Choose a tag to compare

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

  1. 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
  1. JSON Response Helper
  • Success(), Created(), NoContent()
  • BadRequest(), NotFound(), InternalServerError()
  1. Request Utilities
  • ParseJSON() untuk membaca body JSON
  • GetIDFromURL() untuk mengambil parameter ID dari URL
  • GetQueryParam() dan GetQueryParamInt() untuk query string
  1. CRUD Query Builder
  • BuildInsertQuery()
  • BuildUpdateQuery()
  • BuildSelectQuery()
  • CheckRowsAffected()
  1. Middleware
  • CORS() untuk menangani Cross-Origin Resource Sharing
  • Logger() untuk logging HTTP request
  1. 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