变量 – Golang动态变量引用

变量 – Golang动态变量引用,第1张

概述在Go中,我想做这样的事情.我有一个包含许多结构的大对象(使用Google的protobuf).这是一个人为的例子: person.name = "testing"person.address.street = "123 test st"person.address.city = "tester"person.address.zip = 90210person.billing.addres 在Go中,我想做这样的事情.我有一个包含许多结构的大对象(使用Google的protobuf).这是一个人为的例子:
person.name = "testing"person.address.street = "123 test st"person.address.city = "tester"person.address.zip = 90210person.billing.address.same = true

我希望能够动态引用一些东西.例如:

key := "person.address.zip"fmt.Println("the value of key: " + key) // would like to get 90210key := "person.address.city"fmt.Println("the value of key: " + key) // would like to get "tester"

Go有可能吗?如果是的话,我怎么能这样做?基本上,我正在创建一个只包含对象子集的报告,我希望能够创建一个映射文件,用户可以将键/值映射到一起,我的程序将输出值.我有这个在python中工作,但想尝试使用Go 总结

以上是内存溢出为你收集整理的变量 – Golang动态变量引用全部内容,希望文章能够帮你解决变量 – Golang动态变量引用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1293715.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-10
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存