Installation
Requirements
Section titled “Requirements”- Go 1.26 or later
- samber/do v2 in your project
- An active Go module (
go.mod) - The
GOEXPERIMENT=jsonv2build flag (see below)
Install
Section titled “Install”go get github.com/larsartmann/samber-do-auditlogGOEXPERIMENT=jsonv2 (required)
Section titled “GOEXPERIMENT=jsonv2 (required)”Transitive dependencies of do-auditlog use Go’s next-generation encoding/json/v2 packages, which are gated behind the jsonv2 experiment in Go 1.26. Without the flag, the build fails with:
imports github.com/larsartmann/go-ndjsonimports encoding/json/v2: build constraints exclude all Go filesSet the environment variable wherever you build or test code that imports do-auditlog:
export GOEXPERIMENT=jsonv2go build ./...Quick Usage
Section titled “Quick Usage”package main
import ( "github.com/larsartmann/samber-do-auditlog" "github.com/samber/do/v2")
func main() { plugin, err := auditlog.New(auditlog.Config{ Enabled: true, ContainerID: "my-app", }) if err != nil { panic(err) }
injector := do.NewWithOpts(plugin.Opts())
// Register services as usual do.Provide(injector, func(i do.Injector) (*Database, error) { return &Database{}, nil })
// Export when ready plugin.ExportToHTML("audit.html")}Environment Variable
Section titled “Environment Variable”Control the plugin at runtime without code changes:
# Enable (when Config.Enabled is false / zero value)DO_AUDITLOG_ENABLED=trueThe env var is consulted when Config.Enabled is left as the zero value. Accepted values: true, 1, yes. This lets you ship the plugin wired (with Enabled: false) and activate auditing per environment — development, staging, a single debug pod — without recompiling. An explicit Enabled: true in code always wins; the env var cannot disable an explicitly enabled plugin.
Import
Section titled “Import”import "github.com/larsartmann/samber-do-auditlog"Verify Installation
Section titled “Verify Installation”GOEXPERIMENT=jsonv2 go list -m github.com/larsartmann/samber-do-auditlogWhere to go next
Section titled “Where to go next”- Quick Start — complete examples in 60 seconds
- Export Formats — choose the right output format
- Dependency Tracking — how the graph is inferred
- Live Dashboard — watch your container in real time