// 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)) }
func newInventory(dir string) *mosaic.ImageInventory { cache := mosaic.NewFileImageCache(dir) return mosaic.NewImageInventory(cache) }