Got a question on my Twilio library

xuanbao · · 409 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m trying to find a good way to handle the REST responses. Currently I only have two response structs for Calls and Messages. So that I can make the code more &#34;generic&#34; I&#39;ve created an interface so that I can return either of them in my send function in resources.go. However, to actually use the struct in your own code, you must use type assertion. Is there a better way to handle this?</p> <p><a href="https://github.com/stints/twilio" rel="nofollow">github link</a></p> <hr/>**评论:**<br/><br/>gohacker: <pre><p><code>SendMessage(...) Messages</code> and <code>MakeCall(...) Calls</code>. They even can call your unexported <code>send</code> and type-assert.</p> <p>I see that you do not check errors from <code>json.Unmarshal</code>.</p></pre>st1nc1ty: <pre><p>This gave me an idea and I really wish I had seen this. I can just return via the .Call() and .SMS() function the proper response type by asserting what should be before sending back to the end user. Thanks!</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

409 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传