在使用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. .Net反射在项目中的应用

    案例1:项目中可能有多个DAL程序集,每个程序集使用不同的持久化技术或对应不同类型的数据库,但是它们使用同一套接口. 可以在配置文件中配置DAL程序集名称,使用反射加载程序集.创建dal对象. 这样做 ...

  2. 这次是真的换新blog了!

    zlycerqan.xyz zlycerqan.xyz 好麻烦啊...不搞啦...溜辣溜辣 博客又不咕咕咕啦 .

  3. sql语句之union与join的区别

    union查询: 使用 union 可以将多个select语句的查询结果组合起来. 语法: select 字段1,字段2 from table1 union select 字段1,字段2 from t ...

  4. Spring Boot 知识笔记(Filter过滤器)

    Filter也称之为过滤器,它是Servlet技术中最激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Servlet, 静态图片文件或静态 htm ...

  5. SharePoint - Another Way to Delete Site Collection

    I had created a site collection. But there is a problem of web-frontend server (I did not know when ...

  6. Linux常用基础(一)

    1.命令解释器 shell---Unix操作系统 bash---Linux操作系统 本质:根据输入的命令,调用相应的执行程序. 2.Linux下的快捷键 (1)命令和路径补全 Tab键 (2)主键盘的 ...

  7. Flume的Source、Sink总结,及常用使用场景

    数据源Source RPC异构流数据交换 Avro Source Thrift Source 文件或目录变化监听 Exec Source Spooling Directory Source Taild ...

  8. SQL Server ----- 生成sql 脚本

    通过生成sql 脚本进行数据库转移 选中需要进行转移的数据库 点击生成脚本后出现 进入的是简介界面    直接点击下一步 进入到选择对象界面. 按照步骤进行设置     选择你需要的    架构和数据 ...

  9. Delphi阿里云邮件推送【支持单一发信、邮件批量发送和获取指定条件下的发送数据】

    作者QQ:(648437169) 点击下载➨Delphi阿里云邮件推送               阿里云api文档 [Delphi阿里云邮件推送]支持SingleSendMail(单一发信接口). ...

  10. java基础 接口常量

    /** * 接口当中也可以定义"成员变量", 但是必须使用public static final三个关键字进行修饰 * 从效果上看,这其实就是接口的[常用] * 格式: * pub ...