Skip to content

Instantly share code, notes, and snippets.

@flimzy
Created February 8, 2017 16:05
Show Gist options
  • Save flimzy/6329b4bd48a050705fa31e9fd9811cdb to your computer and use it in GitHub Desktop.
Save flimzy/6329b4bd48a050705fa31e9fd9811cdb to your computer and use it in GitHub Desktop.
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