Пример #1
0
// TODO: Instead of calling Unmarshal within Init we should be calling a
// Copy/Clone function instead.
func (i *Item) Init(d recordjar.Decoder, refs map[string]recordjar.Unmarshaler) {
	for x, location := range d.KeywordList("location") {
		if l, ok := refs[location]; ok {
			if l, ok := l.(inventory.Interface); ok {
				if x == 0 {
					l.Add(i)
				} else {
					tmp := &Item{}
					tmp.Unmarshal(d)
					l.Add(tmp)
				}
				log.Printf("Added %s to %s", i.Name(), location)
			} else {
				log.Printf("Cannot add %q to %q: Not an inventory", i.Name(), location)
			}
		} else {
			log.Printf("Cannot add %q to %q: Ref not found", i.Name(), location)
		}
	}
}
Пример #2
0
// Unmarshal should decode the passed recordjar.Decoder into the current
// receiver. A unique ID should be allocated automatically.
func (t *Thing) Unmarshal(d recordjar.Decoder) {
	t.name = d.String("name")
	t.description = d.String(":data:")
	t.aliases = d.KeywordList("aliases")
	t.UID = <-uid.Next
}