Sign in →
1 min read

Go SDK

Zero-dependency Go SDK with http.Handler middleware for any Go web framework.

Updated 2026-07-29Suggest edits
Get the Go SDK
The Go SDK lives in the public repo github.com/aforoai/SDKs under aforo-metering-sdks/go.
View on GitHub Download ZIPgit clone https://github.com/aforoai/SDKs.git

Install & Quickstart#

Add Aforo metering to your Go service. A zero-dependency client with http.Handler and Chi middleware.

Zero dependencies beyond the standard library. The module path is github.com/aforoai/SDKs/aforo-metering-sdks/go.

terminal
# Resolves once the first Go module tag is pushed. Until then, clone + replace:
git clone https://github.com/aforoai/SDKs.git
go.mod
require github.com/aforoai/SDKs/aforo-metering-sdks/go v1.0.0

replace github.com/aforoai/SDKs/aforo-metering-sdks/go => ../SDKs/aforo-metering-sdks/go

Direct Client + Middleware

main.go
package main

import (
    "net/http"
    "os"

    metering "github.com/aforoai/SDKs/aforo-metering-sdks/go"
)

func main() {
    client := metering.NewClient(metering.Options{
        APIKey:  os.Getenv("AFORO_API_KEY"),
        BaseURL: "https://ingest.aforo.ai", // default
    })
    defer client.Close() // flushes the buffer before exit

    // Manual track when you know an event happened:
    client.Track(metering.TrackEvent{
        CustomerID: "cust_acme_001",
        MetricName: "api_calls",
        Quantity:   1,
    })

    // Or meter every request — reads X-Customer-Id, emits after the response:
    mux := http.NewServeMux()
    wrapped := metering.HTTPMiddleware(mux, metering.MiddlewareOptions{
        APIKey: os.Getenv("AFORO_API_KEY"),
    })
    http.ListenAndServe(":8080", wrapped)
}

A Chi adapter is also provided: r.Use(metering.ChiMiddleware(metering.MiddlewareOptions{APIKey: ...})).

See also