// CacheHandler returns a handler that serves HTTP requests // with the contents of the specified cache. func CacheHandler(cache *cdc.DiskCache) http.Handler { handler := &cacheHandler{ DiskCache: cache, host: make(map[string]bool), url: make(map[string][]string), } for _, ustr := range cache.URLs() { u, err := url.Parse(ustr) if err != nil { continue } if len(u.Host) != 0 { if !handler.host[u.Host] { handler.host[u.Host] = true } handler.url[u.Host] = append(handler.url[u.Host], ustr) } } return handler }
func openEntry(cache *cdc.DiskCache, url, addr, dir string) *cdc.Entry { var entry *cdc.Entry var err error if addr != "" { id, era := strconv.ParseUint(addr, 10, 32) if era != nil { log.Fatal(era) } entry, err = cdc.OpenEntry(cdc.CacheAddr(id), dir) } else if url != "" { entry, err = cache.OpenURL(url) } if err != nil { log.Fatal(err) } return entry }