Skip to content

Commit 4fee1be

Browse files
Modified info.Info (add ToString method)
1 parent 43c33d5 commit 4fee1be

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

cli/gpgpdump/facade/facade.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package facade
22

33
import (
4-
"bytes"
54
"fmt"
65
"io"
76
"os"
@@ -68,7 +67,7 @@ var rootCmd = &cobra.Command{
6867
} else if tomlFlag {
6968
result, err = info.TOML()
7069
} else {
71-
result = bytes.NewBufferString(info.String())
70+
result = info.ToString("\t")
7271
err = nil
7372
}
7473
if err != nil {

info/info.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,24 @@ func (i *Info) JSON() (io.Reader, error) {
6060
return buf, nil
6161
}
6262

63-
//Stringer as TOML format
64-
func (i *Info) String() string {
63+
//ToString returns string buffer
64+
func (i *Info) ToString(indent string) *bytes.Buffer {
65+
buf := new(bytes.Buffer)
6566
if i == nil {
66-
return ""
67+
return buf
6768
}
6869
if len(i.Packets) == 0 {
69-
return ""
70+
return buf
7071
}
71-
buf := new(bytes.Buffer)
7272
for _, itm := range i.Packets {
73-
itm.toString("\t", 0, buf)
73+
itm.toString(indent, 0, buf)
7474
}
75-
return buf.String()
75+
return buf
76+
}
77+
78+
//Stringer as TOML format
79+
func (i *Info) String() string {
80+
return i.ToString("\t").String()
7681
}
7782

7883
//Item is information item class

0 commit comments

Comments
 (0)