Integrate AuditKit into your Go application with the official Go SDK. Zero-allocation hot path, context-aware logging, and native support for middleware patterns.
Go is the language of choice for high-performance backend systems, infrastructure tools, and cloud-native applications. The AuditKit Go SDK is designed for performance-critical applications with zero-allocation logging on the hot path, context propagation through context.Context, and native support for net/http middleware patterns. The SDK works with any Go HTTP router including chi, gorilla/mux, gin, and the standard library.
Add the AuditKit Go module.
go get github.com/auditkit/auditkit-goCreate an AuditKit client with your configuration.
import "github.com/auditkit/auditkit-go"
client, err := auditkit.New(auditkit.Config{
APIKey: os.Getenv("AUDITKIT_API_KEY"),
TenantID: "org_123",
})
if err != nil {
log.Fatal(err)
}
defer client.Close()Capture audit events with strongly typed structs.
err := client.Log(ctx, auditkit.Event{
Action: "user.role_changed",
Actor: auditkit.Actor{
ID: userID,
Email: user.Email,
},
Target: auditkit.Target{
Type: "user",
ID: targetUserID,
},
Metadata: map[string]any{
"previous_role": previousRole,
"new_role": newRole,
},
})Use the middleware for automatic request logging.
import "github.com/auditkit/auditkit-go/middleware"
mux := http.NewServeMux()
handler := middleware.AuditLog(client)(mux)
http.ListenAndServe(":8080", handler)Here is a complete example showing AuditKit integrated into a Go application with authentication logging, data access tracking, and explicit event capture.
package main
import (
"log"
"net/http"
"os"
"github.com/auditkit/auditkit-go"
"github.com/auditkit/auditkit-go/middleware"
)
func main() {
client, err := auditkit.New(auditkit.Config{
APIKey: os.Getenv("AUDITKIT_API_KEY"),
TenantID: "org_123",
})
if err != nil {
log.Fatal(err)
}
defer client.Close()
mux := http.NewServeMux()
mux.HandleFunc("POST /api/users/{id}/role", func(w http.ResponseWriter, r *http.Request) {
userID := r.PathValue("id")
user := auth.UserFromContext(r.Context())
previousRole, _ := db.GetUserRole(r.Context(), userID)
newRole := r.FormValue("role")
_ = db.UpdateRole(r.Context(), userID, newRole)
_ = client.Log(r.Context(), auditkit.Event{
Action: "user.role_changed",
Actor: auditkit.Actor{
ID: user.ID,
Email: user.Email,
},
Target: auditkit.Target{
Type: "user",
ID: userID,
},
Metadata: map[string]any{
"previous_role": previousRole,
"new_role": newRole,
"ip_address": r.RemoteAddr,
},
})
w.WriteHeader(http.StatusOK)
})
// Wrap with audit logging middleware
handler := middleware.AuditLog(client)(mux)
log.Fatal(http.ListenAndServe(":8080", handler))
}net/http middleware for automatic request logging
context.Context propagation for tenant and actor resolution
GORM hooks for automatic database change logging
gRPC interceptors for service-to-service audit trails
Buffered async logging for high-throughput systems
Graceful shutdown with pending event flush
Install auditkit-go, create a client with auditkit.New(), and call client.Log() with structured Event objects. Use the middleware package for automatic HTTP request logging with any Go router.
Yes. The AuditKit Go SDK supports buffered async logging for high-throughput applications. Events are batched and sent in the background with configurable buffer size and flush intervals. Call client.Close() to flush pending events on shutdown.
Get started with tamper-proof audit trails in minutes. Open source, from $99/mo.