pin cmd: better struct naming

上级 dd06956d
...@@ -339,11 +339,11 @@ Example: ...@@ -339,11 +339,11 @@ Example:
// For backward compatibility, we accumulate the pins in the same output type as before. // For backward compatibility, we accumulate the pins in the same output type as before.
emit := res.Emit emit := res.Emit
lgcList := map[string]RefObject{} lgcList := map[string]PinLsType{}
if !stream { if !stream {
emit = func(v interface{}) error { emit = func(v interface{}) error {
obj := v.(*PinLsOutputWrapper) obj := v.(*PinLsOutputWrapper)
lgcList[obj.RefKeyObject.Cid] = RefObject{Type: obj.RefKeyObject.Type} lgcList[obj.PinLsObject.Cid] = PinLsType{Type: obj.PinLsObject.Type}
return nil return nil
} }
} }
...@@ -359,7 +359,7 @@ Example: ...@@ -359,7 +359,7 @@ Example:
if !stream { if !stream {
return cmds.EmitOnce(res, &PinLsOutputWrapper{ return cmds.EmitOnce(res, &PinLsOutputWrapper{
RefKeyList: RefKeyList{Keys: lgcList}, PinLsList: PinLsList{Keys: lgcList},
}) })
} }
...@@ -373,14 +373,14 @@ Example: ...@@ -373,14 +373,14 @@ Example:
if stream { if stream {
if quiet { if quiet {
fmt.Fprintf(w, "%s\n", out.RefKeyObject.Cid) fmt.Fprintf(w, "%s\n", out.PinLsObject.Cid)
} else { } else {
fmt.Fprintf(w, "%s %s\n", out.RefKeyObject.Cid, out.RefKeyObject.Type) fmt.Fprintf(w, "%s %s\n", out.PinLsObject.Cid, out.PinLsObject.Type)
} }
return nil return nil
} }
for k, v := range out.RefKeyList.Keys { for k, v := range out.PinLsList.Keys {
if quiet { if quiet {
fmt.Fprintf(w, "%s\n", k) fmt.Fprintf(w, "%s\n", k)
} else { } else {
...@@ -393,24 +393,24 @@ Example: ...@@ -393,24 +393,24 @@ Example:
}, },
} }
type RefKeyObject struct { type PinLsObject struct {
Cid string `json:",omitempty"` Cid string `json:",omitempty"`
Type string `json:",omitempty"` Type string `json:",omitempty"`
} }
type RefObject struct { type PinLsType struct {
Type string Type string
} }
type RefKeyList struct { type PinLsList struct {
Keys map[string]RefObject `json:",omitempty"` Keys map[string]PinLsType `json:",omitempty"`
} }
// Pin ls needs to output two different type depending on if it's streamed or not. // Pin ls needs to output two different type depending on if it's streamed or not.
// We use this to bypass the cmds lib refusing to have interface{} // We use this to bypass the cmds lib refusing to have interface{}
type PinLsOutputWrapper struct { type PinLsOutputWrapper struct {
RefKeyList PinLsList
RefKeyObject PinLsObject
} }
func pinLsKeys(req *cmds.Request, typeStr string, n *core.IpfsNode, api coreiface.CoreAPI, emit func(value interface{}) error) error { func pinLsKeys(req *cmds.Request, typeStr string, n *core.IpfsNode, api coreiface.CoreAPI, emit func(value interface{}) error) error {
...@@ -446,7 +446,7 @@ func pinLsKeys(req *cmds.Request, typeStr string, n *core.IpfsNode, api coreifac ...@@ -446,7 +446,7 @@ func pinLsKeys(req *cmds.Request, typeStr string, n *core.IpfsNode, api coreifac
} }
err = emit(&PinLsOutputWrapper{ err = emit(&PinLsOutputWrapper{
RefKeyObject: RefKeyObject{ PinLsObject: PinLsObject{
Type: pinType, Type: pinType,
Cid: enc.Encode(c.Cid()), Cid: enc.Encode(c.Cid()),
}, },
...@@ -471,7 +471,7 @@ func pinLsAll(req *cmds.Request, typeStr string, n *core.IpfsNode, emit func(val ...@@ -471,7 +471,7 @@ func pinLsAll(req *cmds.Request, typeStr string, n *core.IpfsNode, emit func(val
for _, c := range keyList { for _, c := range keyList {
if keys.Visit(c) { if keys.Visit(c) {
err := emit(&PinLsOutputWrapper{ err := emit(&PinLsOutputWrapper{
RefKeyObject: RefKeyObject{ PinLsObject: PinLsObject{
Type: typeStr, Type: typeStr,
Cid: enc.Encode(c), Cid: enc.Encode(c),
}, },
...@@ -497,7 +497,7 @@ func pinLsAll(req *cmds.Request, typeStr string, n *core.IpfsNode, emit func(val ...@@ -497,7 +497,7 @@ func pinLsAll(req *cmds.Request, typeStr string, n *core.IpfsNode, emit func(val
r := keys.Visit(c) r := keys.Visit(c)
if r { if r {
err := emit(&PinLsOutputWrapper{ err := emit(&PinLsOutputWrapper{
RefKeyObject: RefKeyObject{ PinLsObject: PinLsObject{
Type: typeStr, Type: typeStr,
Cid: enc.Encode(c), Cid: enc.Encode(c),
}, },
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论