Ale*_*uer 13 tags reflection json go
我觉得这应该是一个小问题,但我已经尝试了我能想到的每一种模式,而且我没有运气.我有一个结构,需要由encoding/json
和github.com/zeebo/bencode
包编码.它碰巧包含一个通道,无法通过任何一个包进行编码.因此,它需要携带标签"-"
,以便跳过该字段.
type Index struct {
Data data
Queue chan string `json:"-"`
}
Run Code Online (Sandbox Code Playgroud)
这在json
包编码时有效,但随bencode
包失败.
type Index struct {
Data data
Queue chan string `bencode:"-"`
}
Run Code Online (Sandbox Code Playgroud)
当然,这个街区有免费的问题.我试图代码语法一样json:"-",bencode:"-"
,*:"-"
,"-"
,-
.有解决方案吗?
谢谢你们.
Bri*_*sey 20
当用于编码提示时,空格似乎是struct标记之间的分隔符.
例:
type TaggedStructExample struct {
...
J int `datastore:",noindex" json:"j"`
}
Run Code Online (Sandbox Code Playgroud)
来自:https://developers.google.com/appengine/docs/go/datastore/reference#Properties
在你的情况下,尝试:
type Index struct {
Data data
Queue chan string `bencode:"-" json:"-"`
}
Run Code Online (Sandbox Code Playgroud)