error when trying to convert jwt exp time back to int64 type?

blov · · 416 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>when i try to convert using this code from the claims map</p> <pre><code>time := claims[&#34;exp&#34;].(int64) </code></pre> <p>i get the following error.</p> <p>&#34;interface conversion: interface is float64, not int64&#34;</p> <p>attempting to convert back from interface{} type dosent seem to work. </p> <p>anyone know how to resolve this? thanks</p> <hr/>**评论:**<br/><br/>0xjnml: <pre><p><code>time := int64(claims[&#34;exp&#34;].(float64))</code></p></pre>eoin_ahern: <pre><p>thanks. i dont get it though? </p></pre>RampantGrapefruit: <pre><p>Using <code>val.(int64)</code> is a <em>type assertion</em>. With it you are saying that the interface{} is really an int64, however in this case it is a float64.</p> <p>Using <code>int64(val)</code> is a <em>type conversion</em>. With it you are saying &#34;take this value and convert it into an int64&#34;.</p></pre>hipone: <pre><p>Alternatively instead of jwt.MapClaim use your own type with concrete types and pass it to ParseWithClaims.</p> <p>Usually this is the correct approach.</p></pre>metamatic: <pre><p>You might want to say what library you&#39;re using.</p></pre>eoin_ahern: <pre><p>go jwt . <a href="https://github.com/dgrijalva/jwt-go" rel="nofollow">https://github.com/dgrijalva/jwt-go</a></p></pre>

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

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