chore(security,refactor): extract sanitization and improve code quality (#41)

* chore(security,refactor): extract sanitization and improve code quality

- [x] Extract sanitization functions to dedicated sanitization.go module
- [x] Add comprehensive golangci-lint v2 configuration with security rules
- [x] Replace interface{} with any type throughout codebase
- [x] Add admin API authentication security warning
- [x] Extract WebSocket and stats streaming constants
- [x] Add best-effort error handling comments for resource cleanup
- [x] Expand sensitive field patterns for improved PII redaction
- [x] Simplify safety checks and remove redundant nil validations
- [x] Improve test coverage for password field redaction patterns

* refactor: replace interface{} with any type alias

- [x] Replace all `map[string]interface{}` with `map[string]any`
- [x] Replace all `interface{}` with `any` in function signatures and type definitions
- [x] Update sync.Pool New function returns from `interface{}` to `any`
- [x] Add package documentation comments to 8 package files
- [x] Update type assertions and casts to work with `any` type
This commit is contained in:
2026-01-17 00:04:12 +00:00
committed by GitHub
parent caeae62236
commit 3aa83d4480
42 changed files with 815 additions and 618 deletions
+6 -3
View File
@@ -1,3 +1,6 @@
// Package libpack_logger provides structured JSON logging with configurable
// log levels, caller information, and automatic sensitive data redaction.
// Supports debug, info, warning, and error log levels.
package libpack_logger
import (
@@ -47,13 +50,13 @@ type Logger struct {
// LogMessage represents a log message with optional pairs.
type LogMessage struct {
Pairs map[string]interface{}
Pairs map[string]any
Message string
}
// bufferPool is used to reuse bytes.Buffer for efficiency.
var bufferPool = sync.Pool{
New: func() interface{} {
New: func() any {
return new(bytes.Buffer)
},
}
@@ -132,7 +135,7 @@ func (l *Logger) shouldLog(level int) bool {
// log writes the log message with the given level.
func (l *Logger) log(level int, m *LogMessage) {
if m.Pairs == nil {
m.Pairs = make(map[string]interface{})
m.Pairs = make(map[string]any)
}
m.Pairs[fieldNames["timestamp"]] = time.Now().Format(l.timeFormat)
+1 -1
View File
@@ -24,7 +24,7 @@ func TestLogConcurrentAccess(t *testing.T) {
defer wg.Done()
msg := &LogMessage{
Message: "concurrent log test",
Pairs: map[string]interface{}{
Pairs: map[string]any{
"goroutine_id": id,
},
}