| // Copyright 2018 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| func (s *Size) UnmarshalText(text []byte) error { |
| switch strings.ToLower(string(text)) { |
| func (s Size) MarshalText() ([]byte, error) { |
| func Example_textMarshalJSON() { |
| blob := `["small","regular","large","unrecognized","small","normal","small","large"]` |
| if err := json.Unmarshal([]byte(blob), &inventory); err != nil { |
| counts := make(map[Size]int) |
| for _, size := range inventory { |
| fmt.Printf("Inventory Counts:\n* Small: %d\n* Large: %d\n* Unrecognized: %d\n", |
| counts[Small], counts[Large], counts[Unrecognized]) |