func (s *State) serveWrite(w http.ResponseWriter, r *http.Request) {
	defer r.Body.Close()
	s.lock.Lock()
	defer s.lock.Unlock()
	w.WriteHeader(http.StatusOK)
	var wp WritePost
	s.appendErr(json.NewDecoder(r.Body).Decode(&wp))
	if wp.Source == "" {
		s.appendErr(fmt.Errorf("%v: Got request with no source", s.Hostname))
	} else {
		if s.Received == nil {
			s.Received = map[string]int{}
		}
		s.Received[wp.Source]++
	}
	s.appendErr(json.NewEncoder(w).Encode(&WriteResp{Hostname: s.Hostname}))
}
// serveWrite records the contact in our state.
serveWrite records the contact in our state.
// serveWrite records the contact in our state .
func (s *State) serveWrite(w http.ResponseWriter, r *http.Request) {
	defer r.Body.Close()
	s.lock.Lock()
	defer s.lock.Unlock()
	w.WriteHeader(http.StatusOK)
	var wp WritePost
	s.appendErr(json.NewDecoder(r.Body).Decode(&wp))
	if wp.Source == "" {
		s.appendErr(fmt.Errorf("%v: Got request with no source", s.Hostname))
	} else {
		if s.Received == nil {
			s.Received = map[string]int{}
		}
		s.Received[wp.Source]++
	}
	s.appendErr(json.NewEncoder(w).Encode(&WriteResp{Hostname: s.Hostname}))
}
func ( s * State ) serveWrite ( w http . ResponseWriter , r * http . Request ) { defer r . Body . Close ( ) s . lock . Lock ( ) defer s . lock . Unlock ( ) w . WriteHeader ( http . StatusOK ) var wp WritePost s . appendErr ( json . NewDecoder ( r . Body ) . Decode ( & wp ) ) if wp . Source == " " { s . appendErr ( fmt . Errorf ( " " , s . Hostname ) ) } else { if s . Received == nil { s . Received = map [ string ] int { } } s . Received [ wp . Source ] ++ } s . appendErr ( json . NewEncoder ( w ) . Encode ( & WriteResp { Hostname : s . Hostname } ) ) }
serveWrite records the contact in our state.
serveWrite records the contact in our state .