auditlog

package
v0.0.0-...-e7c744b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(driver Driver, opts ...Option) gin.HandlerFunc

Middleware returns a new HTTP middleware that records audit log entries.

Types

type Clock

type Clock interface {
	Now() time.Time
	Since(time.Time) time.Duration
}

Clock provides time.

type Driver

type Driver interface {
	// Store saves an audit log entry.
	Store(entry Entry) error
}

Driver saves audit log entries.

type Drivers

type Drivers []Driver

Drivers combine multiple drivers into a single instance.

func (Drivers) Store

func (d Drivers) Store(entry Entry) error

type Entry

type Entry struct {
	Time          time.Time
	CorrelationID string
	UserID        uint
	HTTP          HTTPEntry
}

Entry holds all information related to an API call event.

type ErrorHandler

type ErrorHandler = common.ErrorHandler

ErrorHandler is the fundamental interface for error handling.

type HTTPEntry

type HTTPEntry struct {
	ClientIP     string
	UserAgent    string
	Method       string
	Path         string
	RequestBody  string
	StatusCode   int
	ResponseTime int
	ResponseSize int
	Errors       []string
}

HTTPEntry contains details related to an HTTP call for an audit log entry.

type NoopErrorHandler

type NoopErrorHandler = common.NoopErrorHandler

NoopErrorHandler is an error handler that discards every error.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures an audit log middleware.

func WithClock

func WithClock(clock Clock) Option

WithClock sets the clock in an audit log middleware.

func WithErrorHandler

func WithErrorHandler(errorHandler ErrorHandler) Option

WithErrorHandler sets the clock in an audit log middleware.

func WithSensitivePaths

func WithSensitivePaths(sensitivePaths []*regexp.Regexp) Option

WithSensitivePaths marks API call paths as sensitive, causing the log entry to omit the request body.

func WithUserIDExtractor

func WithUserIDExtractor(userIDExtractor func(req *http.Request) uint) Option

WithUserIDExtractor sets the function that extracts the user ID from the request.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL