[英]Multiple tags on the same Go struct member
我覺得這應該是一個小問題,但我已經嘗試了我能想到的每一種模式,而且我沒有運氣。 我有一個結構,需要encoding/json
和github.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:"-"
這樣的標簽語法json:"-",bencode:"-"
, *:"-"
, "-"
, -
。 有解決方案嗎?
謝謝你們。
當用於編碼提示時,空格似乎是struct標記之間的分隔符。
例:
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:"-"`
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.