Ejemplo n.º 1
0
//doGetHead renders records contents(get) or id+timestamp(head) who has id and
// whose stamp is in range of one specified by url.
func doGetHead(w http.ResponseWriter, r *http.Request) {
	s, err := new(w, r)
	if err != nil {
		log.Println(err)
		return
	}
	reg := regexp.MustCompile("^(get|head|removed)/([0-9A-Za-z_]+)/?([-0-9A-Za-z/]*)$")
	m := reg.FindStringSubmatch(s.Path())
	if m == nil {
		log.Println("illegal url", s.Path())
		return
	}
	method, datfile, stamp := m[1], m[2], m[3]
	ca := thread.NewCache(datfile)
	begin, end, id := s.parseStamp(stamp, math.MaxInt32)
	var recs record.Map
	if method == "removed" {
		recs = ca.LoadRecords(record.Removed)
	} else {
		recs = ca.LoadRecords(record.Alive)
	}
	for _, r := range recs {
		if r.InRange(begin, end, id) {
			if method == "get" {
				if err := r.Load(); err != nil {
					log.Println(err)
					continue
				}
				fmt.Fprintln(s.WR, r.Recstr())
				continue
			}
			fmt.Fprintln(s.WR, strings.Replace(r.Idstr(), "_", "<>", -1))
		}
	}
	if method == "get" {
		updateque.UpdatedRecord.Inform(datfile, id, begin, end)
	}
}