func (p *Package) Validate() error {
	cardMap := map[string]*Card{}
	for _, c := range p.Cards {
		if err := c.Validate(); err != nil {
			return errors.Wrapf(err, "card '%s' validation'", c.ID)
		}
		cardMap[c.ID] = c
	}

	cards := make([]*Card, 0, len(cardMap))

	for _, d := range p.Decks {
		if err := d.Validate(); err != nil {
			return errors.Wrapf(err, "deck '%s' validation", d.ID)
		}
		for _, id := range d.Cards.All() {
			c, ok := cardMap[id]
			if !ok {
				return fmt.Errorf("card '%s' listed in deck, but not found in package", id)
			}
			cards = append(cards, c)
			delete(cardMap, id)
		}
	}
	for id := range cardMap {
		return fmt.Errorf("card '%s' found in package, but not in a deck", id)
	}

	modelMap := make(map[string]*Model)
	for _, t := range p.Themes {
		if err := t.Validate(); err != nil {
			return errors.Wrapf(err, "theme '%s' validation", t.ID)
		}
		for _, m := range t.Models {
			modelMap[fmt.Sprintf("%s/%d", t.ID, m.ID)] = m
		}
	}
	for _, n := range p.Notes {
		n.unmarshaling = true
		if err := n.Validate(); err != nil {
			return errors.Wrapf(err, "note '%s' validation", n.ID)
		}
		n.unmarshaling = false
		key := fmt.Sprintf("%s/%d", n.ThemeID, n.ModelID)
		m, ok := modelMap[key]
		if !ok {
			return errors.Errorf("note '%s' has no matching model (%s)", n.ID, key)
		}
		n.Model = m
	}

	return nil
}
// Validate does some basic sanity checking on the package.
Validate does some basic sanity checking on the package.
// Validate does some basic sanity checking on the package .
func (p *Package) Validate() error {
	cardMap := map[string]*Card{}
	for _, c := range p.Cards {
		if err := c.Validate(); err != nil {
			return errors.Wrapf(err, "card '%s' validation'", c.ID)
		}
		cardMap[c.ID] = c
	}
	cards := make([]*Card, 0, len(cardMap))
	for _, d := range p.Decks {
		if err := d.Validate(); err != nil {
			return errors.Wrapf(err, "deck '%s' validation", d.ID)
		}
		for _, id := range d.Cards.All() {
			c, ok := cardMap[id]
			if !ok {
				return fmt.Errorf("card '%s' listed in deck, but not found in package", id)
			}
			cards = append(cards, c)
			delete(cardMap, id)
		}
	}
	for id := range cardMap {
		return fmt.Errorf("card '%s' found in package, but not in a deck", id)
	}
	modelMap := make(map[string]*Model)
	for _, t := range p.Themes {
		if err := t.Validate(); err != nil {
			return errors.Wrapf(err, "theme '%s' validation", t.ID)
		}
		for _, m := range t.Models {
			modelMap[fmt.Sprintf("%s/%d", t.ID, m.ID)] = m
		}
	}
	for _, n := range p.Notes {
		n.unmarshaling = true
		if err := n.Validate(); err != nil {
			return errors.Wrapf(err, "note '%s' validation", n.ID)
		}
		n.unmarshaling = false
		key := fmt.Sprintf("%s/%d", n.ThemeID, n.ModelID)
		m, ok := modelMap[key]
		if !ok {
			return errors.Errorf("note '%s' has no matching model (%s)", n.ID, key)
		}
		n.Model = m
	}
	return nil
}
func ( p * Package ) Validate ( ) error { cardMap := map [ string ] * Card { } for _ , c := range p . Cards { if err := c . Validate ( ) ; err != nil { return errors . Wrapf ( err , " " , c . ID ) } cardMap [ c . ID ] = c } cards := make ( [ ] * Card , 0 , len ( cardMap ) ) for _ , d := range p . Decks { if err := d . Validate ( ) ; err != nil { return errors . Wrapf ( err , " " , d . ID ) } for _ , id := range d . Cards . All ( ) { c , ok := cardMap [ id ] if ! ok { return fmt . Errorf ( " " , id ) } cards = append ( cards , c ) delete ( cardMap , id ) } } for id := range cardMap { return fmt . Errorf ( " " , id ) } modelMap := make ( map [ string ] * Model ) for _ , t := range p . Themes { if err := t . Validate ( ) ; err != nil { return errors . Wrapf ( err , " " , t . ID ) } for _ , m := range t . Models { modelMap [ fmt . Sprintf ( " " , t . ID , m . ID ) ] = m } } for _ , n := range p . Notes { n . unmarshaling = true if err := n . Validate ( ) ; err != nil { return errors . Wrapf ( err , " " , n . ID ) } n . unmarshaling = false key := fmt . Sprintf ( " " , n . ThemeID , n . ModelID ) m , ok := modelMap [ key ] if ! ok { return errors . Errorf ( " " , n . ID , key ) } n . Model = m } return nil }
Validate does some basic sanity checking on the package.
Validate does some basic sanity checking on the package .