1
我很多導致地圖或切片/地圖的陣列,像這樣的查詢:Golang地圖/陣列(非結構)系列化
// package M
type SX map[string]interface{}
type IX map[int64]interface{}
type IAX map[int64][]interface{}
type SAX map[string][]interface{}
type SS map[string]string
type SF map[string]float64
type II map[int64]int64
type IB map[int64]bool
type SI map[string]int64
type IS map[int64]string
type SB map[string]bool
// package A
type X []interface{}
type MSX []map[string]interface{}
所以我可以宣佈它是這樣的:
// import `gitlab.com/kokizzu/gokil/A`
// import `gitlab.com/kokizzu/gokil/M`
values := M.SX{
`orderId`: `1-12-1`,
`apiKey`: `16313c061a8e3288528123bd8`,
`country`: `360`,
`currency`: `360`,
`payType`: 1,
`items`: A.MSX{
M.SX{
`code`: `subscription for 7 days`,
`name`: `Bla bla`,
`price`: price,
},
},
`profile`: M.SX{
`entry`: A.MSX{
M.SX{
`key`: `need_mno_id`,
`value`: `yes`,
},
M.SX{
`key`: `foo`,
`value`: `bar`,
},
},
},
`profile`: A.MSX{
M.SX{`foo`:`bar`,`age`:123},
M.SX{`foo`:`wow`,`age`:234,`currency`:360},
M.SX{`foo`:`such`,`age`:45,`is_admin`:true},
M.SX{`foo`:`wow`,`age`:57,`is_deleted`:true},
},
}
哪些其他的list比encoding/gob
和encoding/json
之一,在支持這種序列化(無需生成結構/架構)的?
github.com/alecthomas/binary
github.com/davecgh/go-xdr/xdr
github.com/Sereal/Sereal/Go/sereal
github.com/ugorji/go/codec
gopkg.in/vmihailenco/msgpack.v2 --> has example for enc/dec-ing a map
labix.org/v2/mgo/bson
github.com/tinylib/msgp (code generator for msgpack)
github.com/golang/protobuf (generated code)
github.com/gogo/protobuf (generated code, optimized version of goprotobuf)
github.com/DeDiS/protobuf (reflection based)
github.com/google/flatbuffers
github.com/hprose/hprose-go/io
github.com/glycerine/go-capnproto
zombiezen.com/go/capnproto2
github.com/andyleap/gencode
github.com/pascaldekloe/colfer
注意:有沒有錯Gob
(目前我使用它們),我只需要爲替代準備(或最好的一個開始)時Gob
不再足夠了(不算快/小足夠),因爲我用它來緩存數據庫(不斷變化的模式)在RAM上查詢結果。
github.com/golang/protobuf作品真的很好。 –