func recieveLogs(w http.ResponseWriter, r *http.Request, ch chan<- *store.Bucket) { defer utils.MeasureT(time.Now(), "http-receiver") if r.Method != "POST" { http.Error(w, "Invalid Request", 400) return } defer r.Body.Close() token, err := utils.ParseToken(r) if err != nil { utils.MeasureE("http-auth", err) http.Error(w, "Invalid Request", 400) return } defer utils.MeasureT(time.Now(), token+"-http-receive") buckets, err := store.NewBucket(token, bufio.NewReader(r.Body)) if err != nil { http.Error(w, "Invalid Request", 400) return } for i := range buckets { ch <- buckets[i] } }
func accept(inbox <-chan *LogRequest, register map[store.BKey]*store.Bucket) { for lreq := range inbox { rdr := bufio.NewReader(bytes.NewReader(lreq.Body)) for bucket := range store.NewBucket(lreq.Token, rdr) { registerLocker.Lock() k := bucket.Key _, present := register[k] if !present { fmt.Printf("at=%q minute=%d name=%s\n", "add-to-register", bucket.Key.Time.Minute(), bucket.Key.Name) register[k] = bucket } else { register[k].Add(bucket) } registerLocker.Unlock() } } }