<p>when i try to convert using this code from the claims map</p>
<pre><code>time := claims["exp"].(int64)
</code></pre>
<p>i get the following error.</p>
<p>"interface conversion: interface is float64, not int64"</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["exp"].(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 "take this value and convert it into an int64".</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'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
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传