MCPcopy
hub / github.com/IBM/sarama / collectQueryStringData

Method collectQueryStringData

examples/http_server/http_server.go:118–141  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

116}
117
118func (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
143type accessLogEntry struct {
144 Method string `json:"method"`

Callers 1

HandlerMethod · 0.95

Calls 2

StringEncoderTypeAlias · 0.92
SendMessageMethod · 0.65

Tested by

no test coverage detected