Re:Go kit: Go in the modern enterprise
by Zikes on Thursday February 12, 2015 @12:09AM
(#9037497)
How about an array of Media?
Output:
Edit: Regarding the MediaType: http://stackoverflow.com/questions/14426366/what-is-an-idiom...
[ Parent
| on HN ]
Re:Go kit: Go in the modern enterprise
by sagichmal on Thursday February 12, 2015 @03:32AM
(#9037979)
PurchaseType doesn't need to be stringly typed. See https://talks.golang.org/2015/json.slide#1.
type PurchaseType byte
const (
Free PurchaseType = iota
Rent
Buy
)
func (t *PurchaseType) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("purchase type should be a string, got %s", data)
}
have, ok := map[string]PurchaseType{"Free": Free, "Rent": Rent, "Buy": Buy}[s]
if !ok {
return fmt.Errorf("invalid purchase type %q", s)
}
*t = have
return nil
}
That's enough to give this output: [{Inception 0.99 Rent} {Johnny Mnemonic 0 Free} {John Wick 17.99 Buy}]
http://play.golang.org/p/dyNVlgmFtu
Re:Go kit: Go in the modern enterprise
by codygman on Thursday February 12, 2015 @12:16AM
(#9037514)
Check out my update if you haven't seen it already.
tl;dr The problem for me personally is when you start making functions based on the type of media and sacrifice type safety if MediaType is a string.