在使用golang实现后端登录逻辑的时候,碰到下面的问题:Cannot convert expression of type interface{} to type []byte

首先介绍下问题出现的场景:使用Redis存储用户登录信息,第三方包使用的是redigo

问题原因:由于从Redis里 取出的数据为interface{}类型,需要先进行类型转换后,才能做后续处理

代码如下:

res, err := redis.String(coon.Do("HGet", "users", id)) //这里如果不进行redis.String()操作,并且这里只能使用redis的函数
user = &User{}
err = json.Unmarshal([]byte(res), user) //则这里就会报错
												

Golang报错:Cannot convert expression of type interface{} to type []byte的更多相关文章

  1. notification 报错the method build() is undefined for the type Notificatin.Builder

    notification 报错the method build() is undefined for the type Notificatin.Builder 这事api版本号太低导致的 Notifi ...

  2. 前端控制台 JavaScript函数报错 SyntaxError: expected expression, got ';' SyntaxError: expected expression, got 'if'

    在火狐浏览器下调试时, 页面报错SyntaxError: expected expression, got ';'或者SyntaxError: expected expression, got 'if ...

  3. JavaScript函数报错SyntaxError: expected expression, got ';'

    故事背景:编写Javaweb项目,在火狐浏览器下运行时firebug报错SyntaxError: expected expression, got ';'或者SyntaxError: expected ...

  4. Xamarin 示例Standard Controls报错:xamarin Failed to compile interface file. See Build Output for details

    Standard Controls 示例下载地址: http://developer.xamarin.com/content/StandardControls/ Xamarin官网上的IOS示例“St ...

  5. pydensecrf安装报错1、UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 29: invalid start byte2、 LINK : fatal error LNK1158: 无法运行“rc.exe” error: command 'D:\\software\\vs2015\\VC\\BIN

    pydensecrf安装报错 1.UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 29: invalid st ...

  6. (type interface {}) to type string

    go 语言开发中,经常会在函数中碰到使用 insterface{} 作为接收任意参数,但是我们接收的数据经常是需要做类型转换,由于是初学者,因此,初次转换我是直接就 func New(paramete ...

  7. sql servel 报错:将 expression 转换为数据类型 int 时出现算术溢出错误。

    执行sql语句:SELECT   AVG( DATEDIFF(s,s.CreatedDate,s.SendDate)  ) AS submitTime FROM dbo.SmsSend AS s    ...

  8. Golang报错mixture of field:value and value initializers

    Golang 在使用匿名成员初始化时,如果出现 mixture of field:value and value initializers 是因为初始化的方式不对,见代码: package main ...

  9. golang 报错illegal rune literal

    记录一下,今天运行一端代码遇到这个报错"illegal rune literal",代码如下: func main() { http.HandleFunc('/login', lo ...

随机推荐

  1. 微信H5页面分享获取JS-SDK

    https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115  微信开发文档: 生成签名之前必须先了解一下jsapi_ti ...

  2. MybatisPlus使用代码生成器遇到的小问题

    MyBatisPlus 在3.0.3版本之前使用代码生成器因为存在默认依赖,所以不需要其他的依赖,项目中使用的是3.0.1的版本,所以不用添加其他依赖,添加之后反倒是会报错,实际上MP官网上已经说明了 ...

  3. 何为pc值

    PC就是程序计数器,就是指挥程序从哪里执行.如果是8位机,每个存储单元存放一个字节,指令有单字节.双字节和3字节.单片机复位时,PC=0000H,而后每执行一条指令,PC根据指令的字节数增加,如图:最 ...

  4. Spring Security教程(二)

    上一篇博客中,Spring Security教程(一),我把用户信息和权限信息放到了xml文件中,这是为了演示如何使用最小的配置就可以使用Spring Security,而实际开发中,用户信息和权限信 ...

  5. 2-1docker图形管理界面

    1.Portainer Shipyard:(停止维护) https://github.com/shipyard/shipyard https://www.portainer.io/installati ...

  6. React-native升级方法

    React-native升级方法: 官网升级说明 中文版官网说明 各个版本差异对比

  7. Qt应用开发常见问题

    Qt判断当前操作系统? 可使用宏判断,例如: #ifdef Q_OS_MAC //mac ... #endif #ifdef Q_OS_LINUX //linux ... #endif #ifdef ...

  8. .net core 读取配置文件的值

    .net core中的配置文件可以存一些自定义的值,我们需要去读取 在配置中添加json: "name": "sealee", "Connection ...

  9. wordpress防止垃圾邮件方法

    wordpress防止垃圾邮件方法 安装NoSpamNX插件然后设置Operating mode 为 Block (recommended) save

  10. vim文本编辑器的使用

    1.简介 vim是vi发展过来的一款文本编辑器,功能非常强大. 2.vim的工作模式 vim有三种工作模式,分别为命令模式.编辑模式.末行模式: 1)命令模式:打开文件之后,默认进入命令模式: 2)编 ...