Exemplo n.º 1
0
// Serve starts up a server. It initializes thumb and mosaic on-disk storage
// and blocks waiting for requests.
func Serve() {
	if err := os.MkdirAll(MosaicsDir, 0755); err != nil {
		log.Fatalf("Failed to create mosaics dir: %s\n", err)
	}
	if err := os.MkdirAll(ThumbsDir, 0755); err != nil {
		log.Fatalf("Failed to create thumbs dir: %s\n", err)
	}
	mosaics = &mosaicInventory{
		cache: mosaic.NewFileImageCache(MosaicsDir),
	}
	thumbs = &thumbInventory{
		tagCacheFunc: func(tag string) mosaic.ImageCache {
			path := path.Join(ThumbsDir, tag)
			if err := os.MkdirAll(path, 0755); err != nil {
				log.Fatalf("Failed to create cache dir: %s\n", err)
			}
			return mosaic.NewFileImageCache(path)
		},
		api:    instagram.NewClient(),
		images: make(map[string]*mosaic.ImageInventory),
		states: make(map[string]chan bool),
	}

	log.Fatal(http.ListenAndServe(HostPort, nil))
}
Exemplo n.º 2
0
func downloadImages(tag string, numImages int, inv *mosaic.ImageInventory) error {
	api := instagram.NewClient()
	fetcher := instagram.NewTagFetcher(api, tag)
	if err := inv.Fetch(fetcher, numImages); err != nil {
		return err
	}
	time.Sleep(1 * time.Second)
	return nil
}