我要解析一些嵌套的JSON,转化成细末类型,像这样:Golang - 通结构作为参数传递给函数
type Config struct {
Mail struct {
From string
To string
Password string
}
Summary struct {
Send bool
Interval int
}
}
现在,我想打电话给每个键的功能(邮件,摘要),我试过它是这样的: utils.StartNewMailer(config.Mail)
问题是,我如何构造被调用的函数,我试图镜像Mail
结构(并将其称为mailConfig
),因为我无法将任意结构作为参数传递。
func StartNewMailer(conf mailConfig){ //...
,但也不管用,我得到以下编译器错误信息: cannot use config.Mail (type struct { From string; To string; Password string }) as type utils.mailConfig in argument to utils.StartNewMailer
我必须在每一个价值传递给被调用的函数或是否有更好的方式来做到这一点?
你是什么意思“我试图镜像'邮件'结构”? – tarrsalah
被调用的函数住在另一个模块,所以我基本上没有出现: '型mailConfig结构{ \t从字符串 \t串 \t密码字符串 }' –