Go backend foundation, production‑ready
from day one.
bkgo is a Hexagonal Architecture foundation package for Go. Plug in adapters, scaffold modules with the CLI, ship multi-language APIs — without reinventing the wheel.
Everything a Go backend needs
One package. No glue code. Just import and build.
Hexagonal Architecture
Contracts (ports) are independent of adapters. Swap PostgreSQL for another DB without touching business logic.
CLI Scaffolding
bkgo new myapp · bkgo g module user. Scaffold projects and generate full modules with one command.
Multi-language (i18n)
Built-in EN, LO (Lao), TH (Thai), ZH (Chinese). Every error response speaks the user's language.
Unit Test Ready
mock/ package ships function-override test doubles for every contract. No mock frameworks needed.
Production Security
RBAC middleware, JWT with alg:none protection, bcrypt passwords, safe error disclosure — secured by default.
Zero Lock-in
Only import what you need. Contracts, adapters, middleware, and CLI are all independent and composable.
Clean code by design
Business logic depends only on contracts — never on concrete adapters.
// internal/user/repository.go
package user
import (
"context"
"errors"
"gorm.io/gorm"
"github.com/BounkhongDev/bkgo/contract"
"github.com/BounkhongDev/bkgo/errs"
)
type repository struct { db contract.ORM }
func NewRepository(db contract.ORM) UserRepository {
return &repository{db: db}
}
func (r *repository) FindByID(
ctx context.Context, id string,
) (*User, error) {
var u User
err := r.db.Session(ctx).First(&u, "id = ?", id).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errs.NotFound("user not found")
}
return &u, err
}// internal/user/usecase_test.go
type mockUserRepo struct {
FindByIDFn func(ctx context.Context, id string) (*user.User, error)
// ... other methods
}
func (m *mockUserRepo) FindByID(ctx context.Context, id string) (*user.User, error) {
return m.FindByIDFn(ctx, id)
}
func TestGetByID_NotFound(t *testing.T) {
repo := &mockUserRepo{
FindByIDFn: func(ctx context.Context, id string) (*user.User, error) {
return nil, errs.NotFound("user not found")
},
}
uc := user.NewUserUsecase(repo)
_, err := uc.GetByID(context.Background(), "missing")
ae, ok := errs.IsAppError(err)
if !ok || ae.Status != 404 {
t.Fatalf("expected 404, got %v", err)
}
}16 packages, one import
Import only what you need. Every package is independent.
bkgo/contractbkgo/configbkgo/adapter/gormdefaultbkgo/adapter/postgresbkgo/adapter/redisbkgo/adapter/miniobkgo/adapter/jwtbkgo/middlewarebkgo/errsbkgo/responsebkgo/i18nbkgo/validatorbkgo/hashbkgo/paginatebkgo/loggerbkgo/mockScaffold in seconds,
not hours.
The bkgo CLI generates a full project structure or individual modules — handler, usecase, repository, and tests — ready to run, following Hexagonal Architecture conventions.
CLI referenceError messages in every language
Set Accept-Language: lo and users get Lao error messages. Built-in EN, LO, TH, ZH — extend with any language.
enResource not found
loບໍ່ພົບຂໍ້ມູນ
thไม่พบข้อมูล
zh资源未找到
Start building in 30 seconds
Install the package, run the CLI, and your first Go module is ready.