Пример #1
0
func (i *thumbInventory) AddTag(tag string) chan bool {
	i.mu.Lock()
	defer i.mu.Unlock()

	// Initialize the inventory.
	if _, ok := i.images[tag]; !ok {
		cache := i.tagCacheFunc(tag)
		i.images[tag] = mosaic.NewImageInventory(cache)

	}
	inv := i.images[tag]

	// Initialize the state.
	if ch, ok := i.states[tag]; ok {
		log.Printf("AddTag(%s) already has it\n", tag)
		return ch
	}
	i.states[tag] = make(chan bool)

	log.Printf("AddTag(%s) beginning fetch\n", tag)
	go func() {
		fetcher := instagram.NewTagFetcher(i.api, tag)
		if err := inv.Fetch(fetcher, ImagesPerTag); err != nil {
			log.Printf("Failed to fetch tag %s: %s", tag, err)
		}
		close(i.states[tag])
	}()

	return i.states[tag]
}
Пример #2
0
func newInventory(dir string) *mosaic.ImageInventory {
	cache := mosaic.NewFileImageCache(dir)
	return mosaic.NewImageInventory(cache)
}