core-go is the shared foundation we build Go services on: configuration, HTTP and Lambda entry points, events over Kafka and SQS, caching, rate limiting, state machines and a set of small typed helpers.
go get github.com/pixie-sh/core-go
Go 1.25+. MIT licensed. The package map is in the README.
Loading configuration, starting a server, handling shutdown, emitting events, caching, logging with a trace ID. None of it is the product, and all of it has to be right.
A service implements one interface and gets bootstrap, health, metrics and graceful shutdown.
Each package is imported on its own. Nothing forces the rest on you.
Errors, logs, IDs and configuration look alike in every service, so moving between them is easy.
pkg has no infrastructure behind it. infra talks to Redis, Kafka, SQS or the database.
| Area | Packages | What you get |
|---|---|---|
| Service | pkg/microservice, pkg/configuration, pkg/context | bootstrap through di-go, config from JSON or TOML with environment placeholders, logger and trace ID in the context |
| HTTP | pkg/comm/http, pkg/comm/http_middlewares, pkg/comm/rest | server, request parsing, logging, metrics, tracing and CORS middlewares, an outbound REST client |
| AWS Lambda | pkg/lambda and subpackages | entry points for API Gateway, SQS and Kafka, with routing |
| Events | infra/events, infra/message_router, pkg/pubsub | typed events, Kafka and SQS producers and consumers, routing and broadcasting |
| State | infra/cache, infra/rate_limiter, infra/state_machine | Redis cache and locks, rate limiting, state machines with conditions and history |
| Operations | infra/cron, infra/database_migrator, pkg/metrics | scheduled jobs, migrations as a service, tracing and metrics |
| Helpers | pkg/types, pkg/uid, pkg/files, pkg/templates | generic slices, sets and maps, scoped IDs, file and image handling, templates |
import "github.com/pixie-sh/core-go/pkg/configuration"
type Config struct {
Port int `json:"port"`
Database struct {
DSN string `json:"dsn"`
} `json:"database"`
}
var cfg Config
_, err := configuration.StructFromJSONBytesWithEnvReplace(
[]byte(`{"port": 8080, "database": {"dsn": "${env.DB_DSN}"}}`),
&cfg,
logger.Logger,
)
// with DB_DSN=postgres://app@db:5432/app
// cfg.Database.DSN == "postgres://app@db:5432/app"import "github.com/pixie-sh/core-go/pkg/uid" const ScopeInvoice uid.Scope = 7 id := uid.NewScoped(ScopeInvoice) fmt.Println(id.String()) // 26-character, time-sortable scope, _ := id.Scope() // 7 same, err := uid.FromString(id.String())
import (
"github.com/pixie-sh/core-go/pkg/types/sets"
"github.com/pixie-sh/core-go/pkg/types/slices"
)
names := slices.Map([]int{1, 2, 2, 3}, func(i int) string {
return fmt.Sprintf("user-%d", i)
})
slices.Deduplicate(names) // [user-1 user-2 user-3]
slices.Contains(names, "user-3") // true
seen := sets.From([]string{"a", "b", "a"}) // 2 items
_, ok := sets.Contains(seen, "b") // trueimport "github.com/pixie-sh/core-go/infra/events"
event := events.NewEventWrapper("evt-1", "invoice.paid", InvoicePaid{InvoiceID: id})
// events.Emit and events.EmitBatch send through the default producers.
// Kafka and SQS implementations live in infra/events/kafka and infra/events/sqs.These libraries run in our own services every day. Use one, or all of them.