func main() { flag.Parse() if *version { fmt.Printf("%v\nBuild: %v\n", VERSION, BUILD_DATE) return } var c httpcache.Cache if *cacheDir != "" { d := diskv.New(diskv.Options{ BasePath: *cacheDir, CacheSizeMax: *cacheSize * 1024 * 1024, }) c = diskcache.NewWithDiskv(d) } else if *cacheSize != 0 { c = httpcache.NewMemoryCache() } p := imageproxy.NewProxy(nil, c) if *whitelist != "" { p.Whitelist = strings.Split(*whitelist, ",") } if *referrers != "" { p.Referrers = strings.Split(*referrers, ",") } if *signatureKey != "" { key := []byte(*signatureKey) if strings.HasPrefix(*signatureKey, "@") { file := strings.TrimPrefix(*signatureKey, "@") var err error key, err = ioutil.ReadFile(file) if err != nil { log.Fatalf("error reading signature file: %v", err) } } p.SignatureKey = key } if *baseURL != "" { var err error p.DefaultBaseURL, err = url.Parse(*baseURL) if err != nil { log.Fatalf("error parsing baseURL: %v", err) } } p.ScaleUp = *scaleUp server := &http.Server{ Addr: *addr, Handler: p, } fmt.Printf("imageproxy (version %v) listening on %s\n", VERSION, server.Addr) err := server.ListenAndServe() if err != nil { log.Fatal("ListenAndServe: ", err) } }
func diskCache(path string) *diskcache.Cache { d := diskv.New(diskv.Options{ BasePath: path, // For file "c0ffee", store file as "c0/ff/c0ffee" Transform: func(s string) []string { return []string{s[0:2], s[2:4]} }, }) return diskcache.NewWithDiskv(d) }
func New(cacheDir string, cacheSize uint64, bucketURL string) *Cache { if cacheDir == "" { cacheDir, _ = ioutil.TempDir("", "disks3cache") } dv := diskv.New(diskv.Options{ BasePath: cacheDir, CacheSizeMax: cacheSize * 1024 * 1024, }) return &Cache{ disk: diskcache.NewWithDiskv(dv), s3: s3cache.New(bucketURL), } }
func main() { // Set server address addr := os.Getenv("ADDRESS") if addr == "" { log.Fatal("No address provided for the imageproxy") } // Set cache var cache httpcache.Cache d := diskv.New(diskv.Options{ BasePath: "/tmp/imageproxy", CacheSizeMax: 500 * 1024 * 1024, }) cache = diskcache.NewWithDiskv(d) // Create proxy p := imageproxy.NewProxy(nil, cache) // Create whitelist if os.Getenv("WHITELIST") != "" { p.Whitelist = strings.Split(os.Getenv("WHITELIST"), ",") } // Create baseurl if os.Getenv("BASEURL") != "" { var err error p.DefaultBaseURL, err = url.Parse(os.Getenv("BASEURL")) if err != nil { log.Fatalf("error parsing baseURL: %v", err) } } p.ScaleUp = true server := &http.Server{ Addr: addr, Handler: p, } fmt.Printf("imageproxy listening on " + addr) err := server.ListenAndServe() if err != nil { log.Fatal("ListenAndServe: ", err) } }