Go Extra Functions and Utilities - a collection of reusable Go utilities for MongoDB tools and general-purpose applications.
go get github.com/simagix/goxDeterministic PII obfuscation with consistent mappings - the same input always produces the same output.
import "github.com/simagix/gox"
o := gox.NewObfuscator()
// Obfuscate various PII types
o.ObfuscateIP("192.168.1.100") // → "192.X.X.100" or "10.X.X.X"
o.ObfuscateHostname("server1.com") // → "tulip.atlanta.local"
o.ObfuscateEmail("user@example.com") // → "begonia@chicago.com"
o.ObfuscateSSN("123-45-6789") // → "XXX-XX-XXXX" (shuffled)
o.ObfuscatePhoneNo("555-123-4567") // → "555-12X-XXXX"
o.ObfuscateMAC("AA:BB:CC:11:22:33") // → "AA:BB:CC:XX:XX:XX"
o.ObfuscateCreditCardNo("4532...") // → "************1234"
o.ObfuscateDate("2024-06-15") // → shifted by DateOffset daysConfiguration Options:
o := gox.NewObfuscator()
// IP obfuscation style
o.IPStyle = gox.IPStyleKeepEnds // 192.168.1.100 → 192.X.X.100 (default)
o.IPStyle = gox.IPStylePrivate // 192.168.1.100 → 10.X.X.X
// Name obfuscation style
o.NameStyle = gox.NameStyleReadable // city/flower names (default)
o.NameStyle = gox.NameStyleHash // host-abc123.local
// Numeric obfuscation
o.Coefficient = 0.917 // multiplier for numbers (default)
o.DateOffset = -42 // days to shift dates (default)PII Detection:
gox.ContainsIP("192.168.1.1") // true
gox.ContainsEmail("user@example.com") // true
gox.ContainsSSN("123-45-6789") // true
gox.ContainsPhoneNo("555-123-4567") // true
gox.ContainsCreditCardNo("4532...") // true (with Luhn check)
gox.ContainsFQDN("server.example.com") // true
gox.IsNamespace("mydb.mycollection") // trueTraversal:
// Obfuscate nested maps
doc := map[string]interface{}{
"ip": "192.168.1.1",
"user": map[string]interface{}{
"email": "user@example.com",
},
}
obfuscated := o.ObfuscateMap(doc)Read files with automatic decompression (gzip, zstd, snappy).
// Auto-detect and decompress
reader, _ := gox.NewReader(file) // from io.Reader
reader, _ := gox.NewFileReader(path) // from file path
// Compression detection
gox.IsGzip(data) // check gzip magic bytes
gox.IsZstd(data) // check zstd magic bytes
gox.IsSnappy(data) // check snappy magic bytesTraverse nested maps with callbacks.
walker := gox.NewMapWalker(func(v interface{}) interface{} {
if s, ok := v.(string); ok {
return strings.ToUpper(s)
}
return v
})
result := walker.Walk(myMap)
level := walker.GetNestedLevel()
maxArrayLen := walker.GetMaxArrayLength()Simple logging utilities.
gox.GetLogger().Info("message")
gox.GetLogger().Error("error occurred")Type conversion utilities.
gox.ToInt(value) // convert any type to int
gox.ToInt64(value) // convert to int64 with error
gox.ToFloat64(value) // convert to float64 with errorGenerate random strings.
gox.GetRandomDigitString(10) // random digits
gox.GetRandomHexString(16) // random hex string
gox.GetRandomUUIDString() // UUID format stringHuman-readable size and duration formatting.
gox.FormatBytes(1024) // "1 KB"
gox.FormatDuration(time.Hour) // "1h"Map that preserves insertion order.
om := gox.NewOrderedMap()
om.Set("key1", "value1")
om.Set("key2", "value2")
for _, key := range om.Keys() {
value := om.Get(key)
}Convert values to strings with formatting.
gox.Stringify(value)HTTP client utilities including digest authentication.
gox.HTTPGet(url, headers)
gox.HTTPDigestAuth(...)Simple web server utilities.
Enhanced wait group utilities.
- hatchet - MongoDB JSON Log Analyzer
- mongo-ftdc - MongoDB FTDC Metrics Viewer