我正在为Golang开发一个Telegram Bot API包装器(我知道已经有一些,但我正在这样做以便学习).我有一个Response结构:
type Response struct {
Ok bool `json:"ok"`
ErrorCode int64 `json:"error_code"`
Description string `json:"description"`
Result interface{} `json:"result"`
}
Run Code Online (Sandbox Code Playgroud)
我不知道实际的类型Result:电报服务器可以返回很多; 我为每个人制作了一个结构,但我不知道哪个结构Result.当Unmarshal荷兰国际集团从HTTP响应到一个JSON Response结构,一切都被正确地装载,除Result.
在我确定Result将是User(例如)的函数中,我正在做user := resp.Result.(*User),但是我在运行时遇到以下错误:
panic: interface conversion: interface {} is map[string]interface {}, not *tgbot.User.所以,Result是一个map[string]interface{}.我怎样才能把它变成一个*User?
谢谢你的回答.