Ejemplo n.º 1
0
Archivo: main.go Proyecto: schorlet/cdc
// 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
}
Ejemplo n.º 2
0
Archivo: main.go Proyecto: schorlet/cdc
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
}