go-core-kit

module
v0.0.0-...-7cab4a1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2026 License: GPL-3.0

README

Go Core Kit

Go Reference Go Report Card

A modular Go toolkit providing abstractions and pluggable implementations for building backend services. Designed around clean interface boundaries so you can swap implementations without changing application code.

Warning: This project is under active development. APIs may change without notice between versions. Not recommended for production use until a stable v1.0.0 release. Use at your own risk.

Installation

go get github.com/aawadallak/go-core-kit

Import only what you need:

import (
    "github.com/aawadallak/go-core-kit/core/logger"
    "github.com/aawadallak/go-core-kit/plugin/logger/zapx"
)

Architecture

The library follows a strict core/plugin separation:

  • core/ defines interfaces and contracts — zero external dependencies beyond the standard library
  • plugin/ provides concrete implementations backed by real infrastructure
  • pkg/ contains shared foundation types and utilities

This means your application code depends only on core/ interfaces. Swap Redis for in-memory caching, SQS for NATS, or Zap for slog — without touching business logic.

Packages

Foundation (pkg/)
Package Description
common Base entity, typed HTTP errors, failure mode classification, request context, dependency validation
core/ptr Generic pointer helpers: New[T], Now(), Safe[T]
Core Interfaces (core/)
Package Description
core/logger Structured logging with severity levels and context propagation
core/cache Key-value caching with TTL, codecs (JSON, GZIP), and Resolver[T] for cache-or-fetch
core/broker Message publishing and subscribing with pluggable codecs
core/repository Generic AbstractRepository[T] and AbstractPaginatedRepository[T, E]
core/conf Configuration loading from multiple providers
core/event Event records with correlation/trace IDs, metadata, and Dispatcher/Publisher
core/idem Idempotency framework with Manager, Store, Locker, and generic Handle[T]
core/job Async job queue with Orchestrator, panic recovery, and graceful shutdown
core/worker Background worker with lifecycle hooks
core/audit Transport-agnostic batching audit log system with generic payload
core/cipher Hashing and verification interface
core/featureflag Feature toggle service with caching and auto-sync
core/txm Transaction manager interface
Plugin Implementations (plugin/)
Package Backend Implements
plugin/logger/zapx Zap core/logger
plugin/logger/slogx log/slog core/logger
plugin/cache/redis go-redis core/cache
plugin/cache/msgpack msgpack core/cache codec
plugin/broker/sqs AWS SQS core/broker
plugin/broker/sns AWS SNS core/broker
plugin/broker/nats NATS core/broker
plugin/broker/natsjetstream NATS JetStream core/broker (with DLQ)
plugin/broker/rmq RabbitMQ core/broker
plugin/abstractrepo GORM core/repository
plugin/conf/ssm AWS SSM Parameter Store core/conf
plugin/conf/vault HashiCorp Vault core/conf
plugin/conf/onepassword 1Password core/conf
plugin/idem/gorm GORM/PostgreSQL core/idem
plugin/idem/inmem In-memory core/idem
plugin/idem/postgres PostgreSQL (raw SQL) core/idem
plugin/event/* Outbox, JetStream, HTTP core/event
plugin/job/jorm GORM core/job
plugin/cipher/bcrypt bcrypt core/cipher
plugin/seal JWT (lestrrat-go/jwx) Data sealing/signatures
plugin/txm/txmgorm GORM core/txm
plugin/otel OpenTelemetry Tracer/Meter helpers
plugin/restchi Chi HTTP server

Quick Start

Logger
package main

import (
    "context"

    "github.com/aawadallak/go-core-kit/core/logger"
    "github.com/aawadallak/go-core-kit/plugin/logger/zapx"
)

func main() {
    // Set up a Zap-backed logger as the global instance
    provider := zapx.NewProvider()
    log := logger.New(logger.WithProvider(provider))
    logger.SetInstance(log)

    ctx := context.Background()
    logger.Of(ctx).Info("service started")
    logger.Of(ctx).InfoS("request processed",
        logger.WithValue("user_id", "abc-123"),
        logger.WithValue("latency_ms", 42),
    )
}
Repository
package main

import (
    "github.com/aawadallak/go-core-kit/common"
    "github.com/aawadallak/go-core-kit/plugin/abstractrepo"
    "gorm.io/gorm"
)

type User struct {
    common.Entity
    Name  string
    Email string `gorm:"uniqueIndex"`
}

func NewUserRepo(db *gorm.DB) (*abstractrepo.AbstractRepository[User], error) {
    return abstractrepo.NewAbstractRepository[User](db,
        abstractrepo.WithMigrate(),
    )
}

// repo.Save(ctx, &user)
// repo.FindOne(ctx, &User{Email: "foo@bar.com"})
// repo.Tx(ctx, func(ctx context.Context) error { ... })
Idempotency
result, err := idem.Handle(ctx, manager, idem.HandleRequest[Order]{
    Key:   idem.BuildOperationKey(idem.WithAction("create_order"), idem.WithEntityID(orderID)),
    Owner: "order-service",
    TTL:   30 * time.Second,
    Run: func(ctx context.Context) (Order, error) {
        return createOrder(ctx, orderID)
    },
})
// result.Executed == true on first call, false on replay
// result.Value contains the Order
Event Publishing with Outbox
// Publish events transactionally via the outbox pattern
publisher := outbox.NewPublisher(outboxRepo, abstractrepo.WithTx)

err := txManager.WithinTransaction(ctx, func(ctx context.Context) error {
    // Business logic...
    order, _ := orderRepo.Save(ctx, &order)

    // Event is written to outbox in the same transaction
    return publisher.Publish(ctx, &OrderCreatedEvent{OrderID: order.ExternalID})
})
// The outbox worker picks up pending events and dispatches them

Design Principles

  • Interface-first — All abstractions are Go interfaces. No framework lock-in.
  • Functional options — Constructors use NewX(opts ...Option) for clean, extensible configuration.
  • Context-first — Every public method accepts context.Context for cancellation and propagation.
  • Generics — Type-safe repositories, idempotency handlers, and broker workers via Go generics.
  • Zero globals by default — Optional global instances for convenience (logger.SetInstance, cache.SetInstance), but everything works with explicit dependency injection.

Requirements

  • Go 1.24+

Contributing

Contributions are welcome! Please open an issue to discuss significant changes before submitting a PR.

License

This project is licensed under the GNU General Public License v3.0.

Directories

Path Synopsis
Package common provides common functionality.
Package common provides common functionality.
core
audit
Package audit provides audit functionality.
Package audit provides audit functionality.
broker
Package broker provides messaging abstractions for publishing and subscribing.
Package broker provides messaging abstractions for publishing and subscribing.
cache
Package cache provides caching abstractions and utilities.
Package cache provides caching abstractions and utilities.
cipher
Package cipher provides cipher functionality.
Package cipher provides cipher functionality.
conf
Package conf provides configuration loading and conversion utilities.
Package conf provides configuration loading and conversion utilities.
event
Package event provides event functionality.
Package event provides event functionality.
featureflag
Package featureflag provides feature flag evaluation and management.
Package featureflag provides feature flag evaluation and management.
idem
Package idem provides idem functionality.
Package idem provides idem functionality.
job
Package job provides job functionality.
Package job provides job functionality.
logger
Package logger provides a structured logging abstraction with multiple severity levels and pluggable providers.
Package logger provides a structured logging abstraction with multiple severity levels and pluggable providers.
ptr
Package ptr provides ptr functionality.
Package ptr provides ptr functionality.
repository
Package repository provides abstract repository patterns for data access.
Package repository provides abstract repository patterns for data access.
txm
Package txm provides txm functionality.
Package txm provides txm functionality.
worker
Package worker provides abstractions for background worker management.
Package worker provides abstractions for background worker management.
plugin
abstractrepo
Package abstractrepo provides abstractrepo functionality.
Package abstractrepo provides abstractrepo functionality.
broker/nats
Package nats provides nats functionality.
Package nats provides nats functionality.
broker/natsjetstream
Package natsjetstream provides NATS JetStream message publishing and consumption.
Package natsjetstream provides NATS JetStream message publishing and consumption.
broker/rmq
Package rmq provides rmq functionality.
Package rmq provides rmq functionality.
broker/sns
Package sns provides an AWS SNS broker implementation.
Package sns provides an AWS SNS broker implementation.
broker/sqs
Package sqs provides an AWS SQS broker implementation.
Package sqs provides an AWS SQS broker implementation.
broker/subscriber
Package subscriber provides message subscription handling utilities.
Package subscriber provides message subscription handling utilities.
cache/msgpack
Package msgpack provides MessagePack encoding and decoding for cache values.
Package msgpack provides MessagePack encoding and decoding for cache values.
cache/redis
Package redis provides Redis caching functionality with configurable options.
Package redis provides Redis caching functionality with configurable options.
cipher/argon2
Package argon2 provides argon2id password hashing functionality.
Package argon2 provides argon2id password hashing functionality.
cipher/bcrypt
Package bcrypt provides bcrypt functionality.
Package bcrypt provides bcrypt functionality.
conf/onepassword
Package onepassword provides a 1Password configuration provider for core/conf.
Package onepassword provides a 1Password configuration provider for core/conf.
conf/ssm
Package ssm provides configuration management using AWS Systems Manager Parameter Store.
Package ssm provides configuration management using AWS Systems Manager Parameter Store.
conf/vault
Package vault provides a HashiCorp Vault configuration provider for core/conf.
Package vault provides a HashiCorp Vault configuration provider for core/conf.
event
Package event provides event functionality.
Package event provides event functionality.
event/eventbroker
Package eventbroker provides event consumption and dispatching via message brokers.
Package eventbroker provides event consumption and dispatching via message brokers.
event/eventhttp
Package eventhttp provides eventhttp functionality.
Package eventhttp provides eventhttp functionality.
event/outbox
Package outbox provides outbox functionality.
Package outbox provides outbox functionality.
idem/gorm
Package gorm provides gorm functionality.
Package gorm provides gorm functionality.
idem/inmem
Package inmem provides inmem functionality.
Package inmem provides inmem functionality.
idem/postgres
Package postgres provides postgres functionality.
Package postgres provides postgres functionality.
job/jorm
Package jorm provides jorm functionality.
Package jorm provides jorm functionality.
logger/slogx
Package slogx provides a structured logging implementation using slog.
Package slogx provides a structured logging implementation using slog.
logger/zapx
Package zapx provides a structured logging implementation using zap.
Package zapx provides a structured logging implementation using zap.
otel
Package otelwrap provides otelwrap functionality.
Package otelwrap provides otelwrap functionality.
rest
Package rest provides HTTP REST server utilities and response helpers.
Package rest provides HTTP REST server utilities and response helpers.
restchi
Package restchi provides chi-based REST server configuration.
Package restchi provides chi-based REST server configuration.
seal
Package seal provides seal functionality.
Package seal provides seal functionality.
seal/provider/gorm
Package sealgorm provides sealgorm functionality.
Package sealgorm provides sealgorm functionality.
txm/txmgorm
Package txmgorm provides txmgorm functionality.
Package txmgorm provides txmgorm functionality.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL