14

我觉得这应该是一个小问题,但我已经尝试了我能想到的所有模式,但我没有任何运气。我有一个结构,需要由 theencoding/jsongithub.com/zeebo/bencode包编码。它恰好包含一个通道,该通道不能被任何一个包编码。因此,它需要携带标签"-",以便跳过该字段。

type Index struct {
    Data data
    Queue chan string `json:"-"`
}

这在由包编码时有效json,但在包中失败bencode

type Index struct {
    Data data
    Queue chan string `bencode:"-"`
}

当然,这个块有互补的问题。我尝试过标签语法,如json:"-",bencode:"-", *:"-", "-", -. 有解决办法吗?

谢谢你们。

4

1 回答 1

21

当用于编码提示时,空格似乎是结构标记之间的分隔符。

例子:

type TaggedStructExample struct {
    ...
    J int `datastore:",noindex" json:"j"`
}

来自:https ://developers.google.com/appengine/docs/go/datastore/reference#Properties

在您的情况下,请尝试:

type Index struct {
    Data data
    Queue chan string `bencode:"-" json:"-"`
}
于 2012-12-04T01:37:32.317 回答