types - Golang gob : type not registered for interface:

标签 types interface go rpc gob

所以我有一个类型String,它是定义的string的别名:

类型字符串字符串

然后我对其应用以下方法:

func (s String) String() string {
    str := "'" + s + "'"
    return string(str)
}

然后,我尝试通过 rpc 发送包含 String 的结构,并收到以下错误:

gob: type not registered for interface: dbUtils.String

我没有定义任何同名的接口(interface),为什么gob认为这是一个接口(interface)?

我在类似的类型上遇到了相同的错误,但使用gob.Register(otherType{})解决了它。 这不适用于 String,大概是因为 string 不是接口(interface)。我是个新手,所以请解释一下发生了什么。

最佳答案

它应该与 String 一起使用,但请确保您传递的是 String() 对象的实例,而不是标识符 String。所以使用 gob.Register(String(""))

关于types - Golang gob : type not registered for interface:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19278392/

相关文章:

interface - 为什么 GoDoc 不显示接口(interface)变量?

go - 如何确保自定义数据结构的编译时安全

api - 在 Go 中使用 pagetoken 遍历 google places API 时遇到问题

Golang Web应用程序安全: should you check if input is valid utf-8?

java - 如何安全地将 int 向下转换为 Short?

interface - 具有类型约束的接口(interface)方法的 F# 实现

c++ - 从缓冲区输入的位

heroku - 我的 Godeps.json 是否正确生成?

haskell - 类型推导在 Haskell 中是如何工作的?

haskell - GHC 7.8 中类型级别自然的行为