Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type ProfileJSON struct {
- Name string `json:"name"`
- Address string `json:"address"`
- CreatedAt int64 `json:"created_at"`
- }
- type Profile struct {
- Name string
- Address string
- Password string
- CreatedAt string
- }
- func (p *Profile) MarshalJSON() ([]byte, error) {
- millis, err := time.Parse(time.RFC3339, p.CreatedAt)
- if err != nil {
- return nil, err
- }
- res := ProfileJSON{
- Name: p.Name,
- Address: p.Address,
- CreatedAt: millis.UnixNano() / 1000000,
- }
- return json.Marshal(&res)
- }
- func main() {
- profile := Profile{
- Name: "name",
- Address: "address",
- Password: "password",
- CreatedAt: "2019-01-22T06:11:43Z",
- }
- res, err := json.Marshal(&profile)
- if err != nil {
- fmt.Println(err)
- }
- fmt.Println(string(res))
- }
Add Comment
Please, Sign In to add comment