Created
August 20, 2022 07:14
-
-
Save Mo3g4u/16e65773d8ffdaa8d1a2247226eb4a44 to your computer and use it in GitHub Desktop.
機密情報を扱うフィールドを定義して出力書式をカスタマイズする
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 ( | |
"encoding/json" | |
"fmt" | |
) | |
type ConfidentialCustomer struct { | |
CustomerID int64 | |
CreditCard CreditCard | |
} | |
type CreditCard string | |
func (c CreditCard) String() string { | |
return "xxxx-xxxx-xxxx-xxxx" | |
} | |
func (c CreditCard) GoString() string { | |
return "xxxx-xxxx-xxxx-xxxx" | |
} | |
func main() { | |
c := ConfidentialCustomer{ | |
CustomerID: 1, | |
CreditCard: "4111-1111-1111-1111", | |
} | |
fmt.Println(c) | |
fmt.Printf("%v\n", c) | |
fmt.Printf("%+v\n", c) | |
fmt.Printf("%#v\n", c) | |
bytes, _ := json.Marshal(c) | |
fmt.Println("JSON: ", string(bytes)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment