Created
February 8, 2017 16:05
-
-
Save flimzy/6329b4bd48a050705fa31e9fd9811cdb to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
) | |
type Customer struct { | |
ID int `json:"id"` | |
FirstName string `json:"firstName"` | |
LastName string `json:"lastName"` | |
} | |
type SafeCustomer struct { | |
Customer | |
ID int `json:"-"` | |
} | |
func main() { | |
userInput := []byte(`{"id": 999999, "firstName": "Jane"}`) | |
customer := Customer{1, "Joe", "Bloggs"} | |
fmt.Println(customer) | |
safeCustomer := &SafeCustomer{Customer: customer} | |
json.Unmarshal(userInput, &updatedCustomer) | |
fmt.Println(customer) | |
} | |
func getCustomerByID(id int) *Customer { | |
return &Customer{id, "Joe", "Bloggs"} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment