2019-06-19 08:30
浏览 191

如何使用map [string] * string

I'm trying to use sarama (Admin mode) to create a topic. Without the ConfigEntries works fine. But I need to define some configs.

I set up the topic config (Here is happening the error):

    tConfigs := map[string]*string{
        "cleanup.policy":      "delete",
        "delete.retention.ms": "36000000",

But then I get an error:

./main.go:99:28: cannot use "delete" (type string) as type *string in map value
./main.go:100:28: cannot use "36000000" (type string) as type *string in map value

I'm trying to use the admin mode like this:

err = admin.CreateTopic(t.Name, &sarama.TopicDetail{
    NumPartitions:     1,
    ReplicationFactor: 3,
    ConfigEntries:     tConfigs,
}, false)

Here is the line from the sarama module that defines CreateTopic() https://github.com/Shopify/sarama/blob/master/admin.go#L18

Basically, I didn't understand how the map of pointers strings works :)

1条回答 默认 最新

相关推荐 更多相似问题