Skip to content

Instantly share code, notes, and snippets.

@donchev7
Last active August 23, 2022 16:31
Show Gist options
  • Save donchev7/b9cd0f20e3d003ad237c9c1c6b7bf20c to your computer and use it in GitHub Desktop.
Save donchev7/b9cd0f20e3d003ad237c9c1c6b7bf20c to your computer and use it in GitHub Desktop.
Prevent secrets ending up in logs
package main
import "fmt"
type secret string
func (s secret) String() string {
return "*****"
}
func (s secret) MarshalJSON() ([]byte, error) {
return json.Marshal(s.String())
}
func main() {
s := secret("secretSauce")
fmt.Println("Secret: ", s)
type TestStruct struct {
APIToken secret
}
oops := TestStruct{APIToken: secret("secretSauce")}
b, _ := json.Marshal(oops)
fmt.Print(string(b))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment