Last active
August 23, 2022 16:31
-
-
Save donchev7/b9cd0f20e3d003ad237c9c1c6b7bf20c to your computer and use it in GitHub Desktop.
Prevent secrets ending up in logs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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