Skip to content

Installation

  • Go 1.26 or later
  • samber/do v2 in your project
  • An active Go module (go.mod)
Terminal window
go get github.com/larsartmann/samber-do-auditlog
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 (default when Config.Enabled is true)
DO_AUDITLOG_ENABLED=true
# Disable — zero hooks, zero cost
DO_AUDITLOG_ENABLED=false

When DO_AUDITLOG_ENABLED is set, it overrides Config.Enabled. This lets you enable auditing in development and disable it in production without recompiling.

import "github.com/larsartmann/samber-do-auditlog"
Terminal window
go list -m github.com/larsartmann/samber-do-auditlog