utils

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

internal/utils/crypto.go

internal/utils/logger.go

internal/utils/metrics.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(ciphertext, key string) (string, error)

Decrypt decrypts the ciphertext using AES-GCM decryption

func Encrypt

func Encrypt(plaintext, key string) (string, error)

Encrypt encrypts the plaintext using AES-GCM encryption

func GenerateSecureKey added in v1.3.1

func GenerateSecureKey(length int) ([]byte, error)

GenerateSecureKey generates a cryptographically secure random key of specified length

func InitLogger

func InitLogger(logFile string) error

InitLogger initializes the logger with a log file

Types

type APIMetrics

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

APIMetrics represents API-specific metrics

func NewAPIMetrics

func NewAPIMetrics() *APIMetrics

NewAPIMetrics creates a new API metrics instance

func (*APIMetrics) RecordAPIRequest

func (am *APIMetrics) RecordAPIRequest(endpoint, method string, statusCode int, duration time.Duration)

RecordAPIRequest records metrics for an API request

func (*APIMetrics) RecordError

func (am *APIMetrics) RecordError(errorType, component string)

RecordError records an error metric

func (*APIMetrics) RecordLLMRequest

func (am *APIMetrics) RecordLLMRequest(provider, model string, tokensUsed int, duration time.Duration)

RecordLLMRequest records metrics for an LLM request

func (*APIMetrics) RecordSceneInteraction

func (am *APIMetrics) RecordSceneInteraction(sceneID, interactionType string)

RecordSceneInteraction records metrics for a scene interaction

func (*APIMetrics) RecordUserAction

func (am *APIMetrics) RecordUserAction(userID, action string)

RecordUserAction records metrics for a user action

func (*APIMetrics) StartMetricsCollection

func (am *APIMetrics) StartMetricsCollection(ctx context.Context)

StartMetricsCollection starts background metrics collection

type Counter

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

Counter metric

type Gauge

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

Gauge metric

type Histogram

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

Histogram metric (simple implementation tracking count, sum, min, max)

type LogEntry

type LogEntry struct {
	Level     string                 `json:"level"`
	Timestamp time.Time              `json:"timestamp"`
	Message   string                 `json:"message"`
	File      string                 `json:"file"`
	Line      int                    `json:"line"`
	Func      string                 `json:"func"`
	Fields    map[string]interface{} `json:"fields,omitempty"`
}

LogEntry represents a log entry

type LogLevel

type LogLevel int

LogLevel represents the logging level

const (
	DEBUG LogLevel = iota
	INFO
	WARNING
	ERROR
	FATAL
)

type Logger

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

Logger represents a structured logger

func GetLogger

func GetLogger() *Logger

GetLogger returns the global logger instance

func (*Logger) Debug

func (l *Logger) Debug(message string, fields map[string]interface{})

Debug logs a debug message

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

Debugf logs a formatted debug message

func (*Logger) Enable

func (l *Logger) Enable(enabled bool)

Enable enables or disables logging

func (*Logger) Error

func (l *Logger) Error(message string, fields map[string]interface{})

Error logs an error message

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

Errorf logs a formatted error message

func (*Logger) Fatal

func (l *Logger) Fatal(message string, fields map[string]interface{})

Fatal logs a fatal message and exits

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...interface{})

Fatalf logs a formatted fatal message and exits

func (*Logger) Info

func (l *Logger) Info(message string, fields map[string]interface{})

Info logs an info message

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

Infof logs a formatted info message

func (*Logger) SetLogLevel

func (l *Logger) SetLogLevel(level LogLevel)

SetLogLevel sets the minimum level for logging

func (*Logger) Warn

func (l *Logger) Warn(message string, fields map[string]interface{})

Warn logs a warning message

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...interface{})

Warnf logs a formatted warning message

type MetricsCollector

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

MetricsCollector collects application metrics

func GetMetricsCollector

func GetMetricsCollector() *MetricsCollector

GetMetricsCollector returns the global metrics collector

func (*MetricsCollector) AddCounter

func (m *MetricsCollector) AddCounter(name string, value int64)

AddCounter adds a value to a counter metric

func (*MetricsCollector) DecGauge

func (m *MetricsCollector) DecGauge(name string)

DecGauge decrements a gauge metric

func (*MetricsCollector) GetCounterValue

func (m *MetricsCollector) GetCounterValue(name string) int64

GetCounterValue gets the current value of a counter

func (*MetricsCollector) GetGauge

func (m *MetricsCollector) GetGauge(name string) int64

GetGauge gets the current value of a gauge

func (*MetricsCollector) GetMetrics

func (m *MetricsCollector) GetMetrics() map[string]interface{}

GetMetrics returns a snapshot of all metrics

func (*MetricsCollector) IncGauge

func (m *MetricsCollector) IncGauge(name string)

IncGauge increments a gauge metric

func (*MetricsCollector) IncrementCounter

func (m *MetricsCollector) IncrementCounter(name string)

IncrementCounter increments a counter metric

func (*MetricsCollector) RecordHistogram

func (m *MetricsCollector) RecordHistogram(name string, value int64)

RecordHistogram records a value in a histogram

func (*MetricsCollector) SetGauge

func (m *MetricsCollector) SetGauge(name string, value int64)

SetGauge sets a gauge metric

Jump to

Keyboard shortcuts

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