()
| 116 | } |
| 117 | |
| 118 | func (s *Server) collectQueryStringData() http.Handler { |
| 119 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 120 | if r.URL.Path != "/" { |
| 121 | http.NotFound(w, r) |
| 122 | return |
| 123 | } |
| 124 | |
| 125 | // We are not setting a message key, which means that all messages will |
| 126 | // be distributed randomly over the different partitions. |
| 127 | partition, offset, err := s.DataCollector.SendMessage(&sarama.ProducerMessage{ |
| 128 | Topic: "important", |
| 129 | Value: sarama.StringEncoder(r.URL.RawQuery), |
| 130 | }) |
| 131 | |
| 132 | if err != nil { |
| 133 | w.WriteHeader(http.StatusInternalServerError) |
| 134 | fmt.Fprintf(w, "Failed to store your data: %s", err) |
| 135 | } else { |
| 136 | // The tuple (topic, partition, offset) can be used as a unique identifier |
| 137 | // for a message in a Kafka cluster. |
| 138 | fmt.Fprintf(w, "Your data is stored with unique identifier important/%d/%d", partition, offset) |
| 139 | } |
| 140 | }) |
| 141 | } |
| 142 | |
| 143 | type accessLogEntry struct { |
| 144 | Method string `json:"method"` |
no test coverage detected