我几乎没有像这样声明的 C 函数
CURLcode curl_wrapper_easy_setopt_long(CURL* curl, CURLoption option, long param);
CURLcode curl_wrapper_easy_setopt_str(CURL* curl, CURLoption option, char* param);
我想像这样将它们公开为一个 Go 函数
func (e *Easy)SetOption(option Option, param interface{})
所以我需要能够在运行时检查 参数 类型。我该怎么做,这是个好主意吗(如果不是,在这种情况下什么是好的做法)?
原文由 Darius Kucinskas 发布,翻译遵循 CC BY-SA 4.0 许可协议
请在此处查看类型断言:
http://golang.org/ref/spec#Type_assertions
我会断言一个合理的类型(字符串,uint64)等,并尽可能保持松散,最后执行到本机类型的转换。