(ctx iris.Context)
| 272 | } |
| 273 | |
| 274 | func postTopicProduceHandler(ctx iris.Context) { |
| 275 | topicName := ctx.Params().Get("topic") |
| 276 | key := ctx.URLParamDefault("key", "default") |
| 277 | |
| 278 | // read the request data and store them as they are (not recommended in production ofcourse, do your own checks here). |
| 279 | body, err := ctx.GetBody() |
| 280 | if err != nil { |
| 281 | fail(ctx, iris.StatusUnprocessableEntity, "unable to read your data: %v", err) |
| 282 | return |
| 283 | } |
| 284 | |
| 285 | partition, offset, err := produceKafkaMessage(topicName, key, body) |
| 286 | if err != nil { |
| 287 | fail(ctx, iris.StatusInternalServerError, "failed to store your data: %v", err) |
| 288 | return |
| 289 | } |
| 290 | |
| 291 | // The tuple (topic, partition, offset) can be used as a unique identifier |
| 292 | // for a message in a Kafka cluster. |
| 293 | ctx.Writef("Your data is stored with unique identifier: %s/%d/%d", topicName, partition, offset) |
| 294 | } |
| 295 | |
| 296 | type message struct { |
| 297 | Time time.Time `json:"time"` |
nothing calls this directly
no test coverage detected
searching dependent graphs…