Created
January 3, 2024 22:16
-
-
Save harmoniemand/11fd22eac150bf0f994d66e3c43c1a17 to your computer and use it in GitHub Desktop.
GOLANG Secrets in Models
This file contains hidden or 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
// thanks to @patrick246 | |
package scrapers | |
import ( | |
"encoding/json" | |
) | |
type Secret string | |
func (s Secret) MarshalJSON() ([]byte, error) { | |
str := string(s) | |
obfuscated := str[0:3] + "***" + str[len(str)-3:] | |
return json.Marshal(obfuscated) | |
} | |
func (s Secret) String() string { | |
str := string(s) | |
obfuscated := str[0:3] + "***" + str[len(str)-3:] | |
return obfuscated | |
} | |
func (s Secret) AsPlainString() string { | |
return string(s) | |
} | |
type MyModel struct { | |
ID string `json:"id"` | |
Name string `json:"name"` | |
Secret Secret `json:"secret"` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment