Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 725bac3

Browse files
committed
Simplify Info (as a map)
Signed-off-by: Vincent Demeester <[email protected]>
1 parent 3f9fc90 commit 725bac3

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

docker/container/container.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ func (c *Container) Info(ctx context.Context, qFlag bool) (project.Info, error)
7676

7777
result := project.Info{}
7878
if qFlag {
79-
result = append(result, project.InfoPart{Key: "Id", Value: c.container.ID})
79+
result["Id"] = c.container.ID
8080
} else {
81-
result = append(result, project.InfoPart{Key: "Name", Value: name(info.Names)})
82-
result = append(result, project.InfoPart{Key: "Command", Value: info.Command})
83-
result = append(result, project.InfoPart{Key: "State", Value: info.Status})
84-
result = append(result, project.InfoPart{Key: "Ports", Value: portString(info.Ports)})
81+
result["Name"] = name(info.Names)
82+
result["Command"] = info.Command
83+
result["State"] = info.Status
84+
result["Ports"] = portString(info.Ports)
8585
}
8686

8787
return result, nil

project/info.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@ import (
66
"text/tabwriter"
77
)
88

9-
// InfoPart holds key/value strings.
10-
type InfoPart struct {
11-
Key, Value string
12-
}
13-
149
// InfoSet holds a list of Info.
1510
type InfoSet []Info
1611

1712
// Info holds a list of InfoPart.
18-
type Info []InfoPart
13+
type Info map[string]string
1914

2015
func (infos InfoSet) String(titleFlag bool) string {
2116
//no error checking, none of this should fail
@@ -37,15 +32,15 @@ func (infos InfoSet) String(titleFlag bool) string {
3732

3833
func writeLine(writer io.Writer, key bool, info Info) {
3934
first := true
40-
for _, part := range info {
35+
for k, v := range info {
4136
if !first {
4237
writer.Write([]byte{'\t'})
4338
}
4439
first = false
4540
if key {
46-
writer.Write([]byte(part.Key))
41+
writer.Write([]byte(k))
4742
} else {
48-
writer.Write([]byte(part.Value))
43+
writer.Write([]byte(v))
4944
}
5045
}
5146

0 commit comments

Comments
 (0)