Skip to content

Installation

  • Go 1.26 or later
  • samber/do v2 in your project
  • An active Go module (go.mod)
  • The GOEXPERIMENT=jsonv2 build flag (see below)
Terminal window
go get github.com/larsartmann/samber-do-auditlog

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-ndjson
imports encoding/json/v2: build constraints exclude all Go files

Set the environment variable wherever you build or test code that imports do-auditlog:

Terminal window
export GOEXPERIMENT=jsonv2
go build ./...
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")
}

Control the plugin at runtime without code changes:

Terminal window
# Enable (when Config.Enabled is false / zero value)
DO_AUDITLOG_ENABLED=true

The 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 "github.com/larsartmann/samber-do-auditlog"
Terminal window
GOEXPERIMENT=jsonv2 go list -m github.com/larsartmann/samber-do-auditlog