dedup

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 3 Imported by: 0

README

Log Redaction

This package provides sensitive data redaction for log messages.

Usage

import "github.com/hrygo/hotplex/chatapps/dedup"

// Before logging
logger.Info("Config loaded", "token", dedup.RedactSensitiveData(config.BotToken))

// Or wrap your logger
type RedactedLogger struct {
    logger *slog.Logger
}

func (r *RedactedLogger) Info(msg string, args ...any) {
    for i := 1; i < len(args); i += 2 {
        if str, ok := args[i].(string); ok {
            args[i] = dedup.RedactSensitiveData(str)
        }
    }
    r.logger.Info(msg, args...)
}

Supported Patterns

  • Slack tokens: xoxb-*, xoxp-*, xoxa-*, xoxr-*
  • GitHub tokens: ghp_*, gho_*, github_pat_*
  • API keys: sk-*, Bearer *

Performance

  • Single token: ~237 ns/op
  • Memory: 144 B/op, 2 allocs/op

Security Notes

  • Always redact before logging
  • Never log raw tokens/secrets
  • Use environment variables for sensitive config

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RedactSensitiveData

func RedactSensitiveData(s string) string

RedactSensitiveData redacts sensitive information from log messages This prevents tokens, secrets, and keys from being logged

Types

type Deduplicator

type Deduplicator struct {
	// contains filtered or unexported fields
}

Deduplicator implements event deduplication using LRU cache

func NewDeduplicator

func NewDeduplicator(window, cleanupInt time.Duration) *Deduplicator

NewDeduplicator creates a new event deduplicator

func (*Deduplicator) Check

func (d *Deduplicator) Check(key string) bool

Check checks if an event is duplicate Returns true if duplicate, false if new

func (*Deduplicator) Shutdown

func (d *Deduplicator) Shutdown()

Shutdown stops the deduplicator

func (*Deduplicator) Size

func (d *Deduplicator) Size() int

Size returns the current cache size (for testing)

type KeyStrategy

type KeyStrategy interface {
	// GenerateKey generates a deduplication key from event data
	GenerateKey(eventData map[string]any) string
}

KeyStrategy defines the interface for generating deduplication keys

type SlackKeyStrategy

type SlackKeyStrategy struct{}

SlackKeyStrategy implements KeyStrategy for Slack events

func NewSlackKeyStrategy

func NewSlackKeyStrategy() *SlackKeyStrategy

NewSlackKeyStrategy creates a new Slack key strategy

func (*SlackKeyStrategy) GenerateKey

func (s *SlackKeyStrategy) GenerateKey(eventData map[string]any) string

GenerateKey generates a deduplication key for Slack events Format: {platform}:{event_type}:{channel}:{event_ts}

Jump to

Keyboard shortcuts

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