export

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package export provides pluggable audit log export with pagination.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalJSONFunc

func MarshalJSONFunc() func(any) ([]byte, error)

MarshalJSONFunc returns the current JSON marshaler for test inspection.

func OpenFileFunc

func OpenFileFunc() func(string) (io.WriteCloser, error)

OpenFileFunc returns the current file opener for test inspection.

func SetMarshalJSONFunc

func SetMarshalJSONFunc(
	fn func(any) ([]byte, error),
)

SetMarshalJSONFunc replaces the JSON marshaler. Used by tests.

func SetOpenFileFunc

func SetOpenFileFunc(
	fn func(string) (io.WriteCloser, error),
)

SetOpenFileFunc replaces the file opener. Used by tests.

Types

type Exporter

type Exporter interface {
	Open(ctx context.Context) error
	Write(ctx context.Context, entry client.AuditEntry) error
	Close(ctx context.Context) error
}

Exporter writes audit entries to a backend.

type Fetcher

type Fetcher func(
	ctx context.Context,
	limit int,
	offset int,
) ([]client.AuditEntry, int, error)

Fetcher retrieves a page of audit entries. Returns the entries, total count, and any error.

type FileExporter

type FileExporter struct {
	Path string
	// contains filtered or unexported fields
}

FileExporter writes audit entries as JSON lines to a file.

func NewFileExporter

func NewFileExporter(
	path string,
) *FileExporter

NewFileExporter creates a new FileExporter for the given path.

func (*FileExporter) Close

func (e *FileExporter) Close(
	_ context.Context,
) error

Close flushes the buffer and closes the file.

func (*FileExporter) Open

func (e *FileExporter) Open(
	_ context.Context,
) error

Open creates the output file and prepares for writing.

func (*FileExporter) Write

func (e *FileExporter) Write(
	_ context.Context,
	entry client.AuditEntry,
) error

Write marshals an audit entry to JSON and writes it as a single line.

type ProgressFunc

type ProgressFunc func(exported int, total int)

ProgressFunc is called after each batch with the running exported count and total.

type Result

type Result struct {
	TotalEntries    int
	ExportedEntries int
}

Result holds export outcome.

func Run

func Run(
	ctx context.Context,
	logger *slog.Logger,
	fetcher Fetcher,
	exporter Exporter,
	batchSize int,
	onProgress ProgressFunc,
) (*Result, error)

Run paginates through audit entries and writes each to the exporter.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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