首页 > 解决方案 > 在没有泛型的情况下在 Golang 中重用类似的代码

问题描述

鉴于我有一个 MyMap 类型的变量

*map[uuid.UUID][]*Thing

和这样的一段代码:

h.MyMap[id] = append(h.MyMap[id], &thingA)

// other stuff with MyMap like this, later:

h.MyMapp[id][k] = &thingB

// and so on... the actual code is way more complex

和上面一样的代码,除了它使用类型的映射:

*map[int64][]*Thing

有没有一种 Golang 方法来干燥它并编写一个在一个地方执行类似代码的助手?

谢谢你。

标签: gogenericssoftware-design

解决方案


[我]有没有一种 Golang 方法来干燥它并编写一个在一个地方执行类似代码的助手?

不。


推荐阅读