Masking sensitive data is crucial for maintaining data privacy and security, especially when logging information in applications. In Go, you can utilize the zerolog library to efficiently log events while masking sensitive data such as passwords, credit card numbers, or personal identification details.
Below is an example demonstrating how to mask sensitive data using zerolog in Go:
package main
import (
"os"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func main() {
// Initialize zerolog
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
logger := zerolog.New(os.Stdout).With().Timestamp().Logger()
username := "user123"
password := "superSecretPass!"
creditCard := "1234-5678-9012-3456"
// Masking sensitive data
logger.Info().
Str("username", username).
Str("password", maskString(password)).
Str("credit_card", maskString(creditCard)).
Msg("User logged in")
}
// function to mask a string
func maskString(s string) string {
return "****" // Masked representation
}
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?