Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-kit

A lightweight, framework-agnostic Go module of shared utilities for building RESTful APIs. Extracted from production services at porygon-labs.

Packages

Package Purpose External deps
logger Global slog.Logger with Init/Default and convenience wrappers None (stdlib)
response Consistent JSON API envelope ({ meta, data }) via http.ResponseWriter None (stdlib)
hash Sqids-based integer ID obfuscation with canonical verification sqids-go
telemetry OTel OTLP gRPC tracer setup + auto-named span helper OTel SDK
config Generic Load[T any]() — .env + env vars into your struct caarlos0/env, godotenv

Install

go get github.com/porygon-labs/go-kit

Usage

import (
    "github.com/porygon-labs/go-kit/logger"
    "github.com/porygon-labs/go-kit/response"
    "github.com/porygon-labs/go-kit/hash"
    "github.com/porygon-labs/go-kit/telemetry"
)

Import only what you need. Unused packages don't pull their dependencies into your go.mod.

logger

logger.Init(logger.New("debug", "json"))

logger.Info("server started", "port", 8080)
logger.Error("something broke", "error", err)

response

func handler(w http.ResponseWriter, r *http.Request) {
    response.OK(w, map[string]string{"hello": "world"})
    // → {"meta":{"is_success":true,"message":"OK"},"data":{"hello":"world"}}
}

Works with any framework that exposes http.ResponseWriter — Echo, Gin, Chi, or plain net/http.

hash

h, _ := hash.NewHash("abcdefghijklmnopqrstuvwxyz0123456789")
encoded, _ := h.Encode(42)       // → "someHash"
ids, _ := h.Decode(encoded)      // → []int64{42}

telemetry

shutdown, _ := telemetry.Init(ctx, "my-service", "otel-collector:4317")
defer shutdown(ctx)

// Spans auto-named by caller function:
ctx, end := telemetry.StartSpan(ctx)
defer end()

Framework support

go-kit targets the standard library. Tested with:

  • Echo v5 — pass c.Response() as http.ResponseWriter
  • Gin — pass c.Writer as http.ResponseWriter
  • Chi / net/http — pass w directly

License

MIT — see LICENSE.

About

go-kit is a lightweight Go module of framework-agnostic utilities

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages