Documentation ¶
Overview ¶
Package scrub implements a scrubbing utility to hide sensitive fields from a struct.
This utility can be used to purge sensitive fields from a deeply nested struct at any level. This is useful for scenarios such as logging structures which may contain user passwords, secret keys, passphrases, etc.
Notes & Caveates
Only exported fields of a struct can be scrubbed (fields starting with a capital letter). Reflect package cannot modify unexported (private) fields. Also, The input struct must be passed by its address, otherwise the values of its fields cannot be changed.
Example
T := testScrub{ Username: "administrator", Password: "my_secret_passphrase", Codes: []string{"pass1", "pass2", "pass3"}, } fieldsToScrub := map[string]bool{"password": true, "codes": true} out := Scrub(&T, fieldsToScrub) log.Println(out) OUTPUT: {username:administrator Password:******** Codes:[******** ******** ********]}
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultToScrub = map[string]bool{ "password": true, }
DefaultToScrub contains default field names to scrub. NOTE: these fields should be all lowercase. Comparison is case insensitive.
Functions ¶
Types ¶
This section is empty.