MCPcopy Create free account
hub / github.com/kataras/iris / postTopicProduceHandler

Function postTopicProduceHandler

_examples/kafka-api/main.go:274–294  ·  view source on GitHub ↗
(ctx iris.Context)

Source from the content-addressed store, hash-verified

272}
273
274func 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
296type message struct {
297 Time time.Time `json:"time"`

Callers

nothing calls this directly

Calls 7

produceKafkaMessageFunction · 0.85
ParamsMethod · 0.80
URLParamDefaultMethod · 0.80
GetBodyMethod · 0.80
WritefMethod · 0.80
failFunction · 0.70
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…