簡體   English   中英

同一Go結構成員上的多個標記

[英]Multiple tags on the same Go struct member

我覺得這應該是一個小問題,但我已經嘗試了我能想到的每一種模式,而且我沒有運氣。 我有一個結構,需要encoding/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:"-"這樣的標簽語法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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM