From 7589722e938f0e870697cefff5abd68f87f249ec Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 21 Aug 2025 13:55:02 +0200 Subject: [PATCH 01/11] cli/command/network: formatWrite: inline vars and use struct literals Signed-off-by: Sebastiaan van Stijn --- cli/command/network/formatter.go | 38 ++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/cli/command/network/formatter.go b/cli/command/network/formatter.go index 59f97060c..84addffe9 100644 --- a/cli/command/network/formatter.go +++ b/cli/command/network/formatter.go @@ -50,28 +50,32 @@ func FormatWrite(fmtCtx formatter.Context, networks []network.Summary) error { // formatWrite writes the context. func formatWrite(fmtCtx formatter.Context, networks []network.Summary) error { - render := func(format func(subContext formatter.SubContext) error) error { + networkCtx := networkContext{ + HeaderContext: formatter.HeaderContext{ + Header: formatter.SubHeaderContext{ + "ID": networkIDHeader, + "Name": formatter.NameHeader, + "Driver": formatter.DriverHeader, + "Scope": formatter.ScopeHeader, + "IPv4": ipv4Header, + "IPv6": ipv6Header, + "Internal": internalHeader, + "Labels": formatter.LabelsHeader, + "CreatedAt": formatter.CreatedAtHeader, + }, + }, + } + return fmtCtx.Write(&networkCtx, func(format func(subContext formatter.SubContext) error) error { for _, nw := range networks { - networkCtx := &networkContext{trunc: fmtCtx.Trunc, n: nw} - if err := format(networkCtx); err != nil { + if err := format(&networkContext{ + trunc: fmtCtx.Trunc, + n: nw, + }); err != nil { return err } } return nil - } - networkCtx := networkContext{} - networkCtx.Header = formatter.SubHeaderContext{ - "ID": networkIDHeader, - "Name": formatter.NameHeader, - "Driver": formatter.DriverHeader, - "Scope": formatter.ScopeHeader, - "IPv4": ipv4Header, - "IPv6": ipv6Header, - "Internal": internalHeader, - "Labels": formatter.LabelsHeader, - "CreatedAt": formatter.CreatedAtHeader, - } - return fmtCtx.Write(&networkCtx, render) + }) } type networkContext struct { From 8cb8056efa7a0b0489b9d48a3302ea5b1c7f764a Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 21 Aug 2025 14:03:54 +0200 Subject: [PATCH 02/11] cli/command/image: historyWrite: inline vars and use struct literals Signed-off-by: Sebastiaan van Stijn --- cli/command/image/formatter_history.go | 33 +++++++++++++++----------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/cli/command/image/formatter_history.go b/cli/command/image/formatter_history.go index 9d6d243fa..3acd6dbd3 100644 --- a/cli/command/image/formatter_history.go +++ b/cli/command/image/formatter_history.go @@ -51,25 +51,30 @@ func HistoryWrite(fmtCtx formatter.Context, human bool, histories []image.Histor // historyWrite writes the context func historyWrite(fmtCtx formatter.Context, human bool, histories []image.HistoryResponseItem) error { - render := func(format func(subContext formatter.SubContext) error) error { + historyCtx := &historyContext{ + HeaderContext: formatter.HeaderContext{ + Header: formatter.SubHeaderContext{ + "ID": historyIDHeader, + "CreatedSince": formatter.CreatedSinceHeader, + "CreatedAt": formatter.CreatedAtHeader, + "CreatedBy": createdByHeader, + "Size": formatter.SizeHeader, + "Comment": commentHeader, + }, + }, + } + return fmtCtx.Write(historyCtx, func(format func(subContext formatter.SubContext) error) error { for _, history := range histories { - historyCtx := &historyContext{trunc: fmtCtx.Trunc, h: history, human: human} - if err := format(historyCtx); err != nil { + if err := format(&historyContext{ + trunc: fmtCtx.Trunc, + h: history, + human: human, + }); err != nil { return err } } return nil - } - historyCtx := &historyContext{} - historyCtx.Header = formatter.SubHeaderContext{ - "ID": historyIDHeader, - "CreatedSince": formatter.CreatedSinceHeader, - "CreatedAt": formatter.CreatedAtHeader, - "CreatedBy": createdByHeader, - "Size": formatter.SizeHeader, - "Comment": commentHeader, - } - return fmtCtx.Write(historyCtx, render) + }) } type historyContext struct { From 70033b78d41dbb5c9c56d3b57cd778b4ac8c72fa Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 21 Aug 2025 14:15:26 +0200 Subject: [PATCH 03/11] cli/command/checkpoint: formatWrite: inline vars and use struct literals Signed-off-by: Sebastiaan van Stijn --- cli/command/checkpoint/formatter.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/cli/command/checkpoint/formatter.go b/cli/command/checkpoint/formatter.go index 10706343a..05f32d491 100644 --- a/cli/command/checkpoint/formatter.go +++ b/cli/command/checkpoint/formatter.go @@ -34,15 +34,21 @@ func FormatWrite(fmtCtx formatter.Context, checkpoints []checkpoint.Summary) err // formatWrite writes formatted checkpoints using the Context func formatWrite(fmtCtx formatter.Context, checkpoints []checkpoint.Summary) error { - render := func(format func(subContext formatter.SubContext) error) error { + cpContext := &checkpointContext{ + HeaderContext: formatter.HeaderContext{ + Header: formatter.SubHeaderContext{ + "Name": checkpointNameHeader, + }, + }, + } + return fmtCtx.Write(cpContext, func(format func(subContext formatter.SubContext) error) error { for _, cp := range checkpoints { if err := format(&checkpointContext{c: cp}); err != nil { return err } } return nil - } - return fmtCtx.Write(newCheckpointContext(), render) + }) } type checkpointContext struct { @@ -50,14 +56,6 @@ type checkpointContext struct { c checkpoint.Summary } -func newCheckpointContext() *checkpointContext { - cpCtx := checkpointContext{} - cpCtx.Header = formatter.SubHeaderContext{ - "Name": checkpointNameHeader, - } - return &cpCtx -} - func (c *checkpointContext) MarshalJSON() ([]byte, error) { return formatter.MarshalJSON(c) } From 3d2bd97a82c03fd6f990ae9d5abd0046293e939c Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 21 Aug 2025 14:25:06 +0200 Subject: [PATCH 04/11] cli/command/config: formatWrite: inline vars and use struct literals Signed-off-by: Sebastiaan van Stijn --- cli/command/config/formatter.go | 34 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/cli/command/config/formatter.go b/cli/command/config/formatter.go index 046a6e634..3d6b0c175 100644 --- a/cli/command/config/formatter.go +++ b/cli/command/config/formatter.go @@ -59,7 +59,18 @@ func FormatWrite(fmtCtx formatter.Context, configs []swarm.Config) error { // formatWrite writes the context func formatWrite(fmtCtx formatter.Context, configs []swarm.Config) error { - render := func(format func(subContext formatter.SubContext) error) error { + cCtx := &configContext{ + HeaderContext: formatter.HeaderContext{ + Header: formatter.SubHeaderContext{ + "ID": configIDHeader, + "Name": formatter.NameHeader, + "CreatedAt": configCreatedHeader, + "UpdatedAt": configUpdatedHeader, + "Labels": formatter.LabelsHeader, + }, + }, + } + return fmtCtx.Write(cCtx, func(format func(subContext formatter.SubContext) error) error { for _, config := range configs { configCtx := &configContext{c: config} if err := format(configCtx); err != nil { @@ -67,21 +78,7 @@ func formatWrite(fmtCtx formatter.Context, configs []swarm.Config) error { } } return nil - } - return fmtCtx.Write(newConfigContext(), render) -} - -func newConfigContext() *configContext { - cCtx := &configContext{} - - cCtx.Header = formatter.SubHeaderContext{ - "ID": configIDHeader, - "Name": formatter.NameHeader, - "CreatedAt": configCreatedHeader, - "UpdatedAt": configUpdatedHeader, - "Labels": formatter.LabelsHeader, - } - return cCtx + }) } type configContext struct { @@ -140,7 +137,7 @@ func inspectFormatWrite(fmtCtx formatter.Context, refs []string, getRef inspect. if fmtCtx.Format != configInspectPrettyTemplate { return inspect.Inspect(fmtCtx.Output, refs, string(fmtCtx.Format), getRef) } - render := func(format func(subContext formatter.SubContext) error) error { + return fmtCtx.Write(&configInspectContext{}, func(format func(subContext formatter.SubContext) error) error { for _, ref := range refs { configI, _, err := getRef(ref) if err != nil { @@ -155,8 +152,7 @@ func inspectFormatWrite(fmtCtx formatter.Context, refs []string, getRef inspect. } } return nil - } - return fmtCtx.Write(&configInspectContext{}, render) + }) } type configInspectContext struct { From 1a433cdbdb5c8d7b87d3d00b13714f11f655f59d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 21 Aug 2025 14:38:46 +0200 Subject: [PATCH 05/11] cli/command/node: inline vars and use struct literals Signed-off-by: Sebastiaan van Stijn --- cli/command/node/formatter.go | 41 +++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/cli/command/node/formatter.go b/cli/command/node/formatter.go index 4111494ba..a3c77bc6d 100644 --- a/cli/command/node/formatter.go +++ b/cli/command/node/formatter.go @@ -114,27 +114,31 @@ func FormatWrite(fmtCtx formatter.Context, nodes []swarm.Node, info system.Info) // formatWrite writes the context. func formatWrite(fmtCtx formatter.Context, nodes []swarm.Node, info system.Info) error { - render := func(format func(subContext formatter.SubContext) error) error { + nodeCtx := &nodeContext{ + HeaderContext: formatter.HeaderContext{ + Header: formatter.SubHeaderContext{ + "ID": nodeIDHeader, + "Self": selfHeader, + "Hostname": hostnameHeader, + "Status": formatter.StatusHeader, + "Availability": availabilityHeader, + "ManagerStatus": managerStatusHeader, + "EngineVersion": engineVersionHeader, + "TLSStatus": tlsStatusHeader, + }, + }, + } + return fmtCtx.Write(nodeCtx, func(format func(subContext formatter.SubContext) error) error { for _, node := range nodes { - nodeCtx := &nodeContext{n: node, info: info} - if err := format(nodeCtx); err != nil { + if err := format(&nodeContext{ + n: node, + info: info, + }); err != nil { return err } } return nil - } - nodeCtx := nodeContext{} - nodeCtx.Header = formatter.SubHeaderContext{ - "ID": nodeIDHeader, - "Self": selfHeader, - "Hostname": hostnameHeader, - "Status": formatter.StatusHeader, - "Availability": availabilityHeader, - "ManagerStatus": managerStatusHeader, - "EngineVersion": engineVersionHeader, - "TLSStatus": tlsStatusHeader, - } - return fmtCtx.Write(&nodeCtx, render) + }) } type nodeContext struct { @@ -205,7 +209,7 @@ func inspectFormatWrite(fmtCtx formatter.Context, refs []string, getRef inspect. if fmtCtx.Format != nodeInspectPrettyTemplate { return inspect.Inspect(fmtCtx.Output, refs, string(fmtCtx.Format), getRef) } - render := func(format func(subContext formatter.SubContext) error) error { + return fmtCtx.Write(&nodeInspectContext{}, func(format func(subContext formatter.SubContext) error) error { for _, ref := range refs { nodeI, _, err := getRef(ref) if err != nil { @@ -220,8 +224,7 @@ func inspectFormatWrite(fmtCtx formatter.Context, refs []string, getRef inspect. } } return nil - } - return fmtCtx.Write(&nodeInspectContext{}, render) + }) } type nodeInspectContext struct { From aa39a7e7bec70c50f44251493c51e370b9273d35 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 21 Aug 2025 14:43:08 +0200 Subject: [PATCH 06/11] cli/command/plugin: inline vars and use struct literals Signed-off-by: Sebastiaan van Stijn --- cli/command/plugin/formatter.go | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/cli/command/plugin/formatter.go b/cli/command/plugin/formatter.go index 4407745eb..ff545bddd 100644 --- a/cli/command/plugin/formatter.go +++ b/cli/command/plugin/formatter.go @@ -53,24 +53,28 @@ func FormatWrite(fmtCtx formatter.Context, plugins []*plugin.Plugin) error { // formatWrite writes the context func formatWrite(fmtCtx formatter.Context, plugins []*plugin.Plugin) error { - render := func(format func(subContext formatter.SubContext) error) error { + pluginCtx := &pluginContext{ + HeaderContext: formatter.HeaderContext{ + Header: formatter.SubHeaderContext{ + "ID": pluginIDHeader, + "Name": formatter.NameHeader, + "Description": formatter.DescriptionHeader, + "Enabled": enabledHeader, + "PluginReference": formatter.ImageHeader, + }, + }, + } + return fmtCtx.Write(pluginCtx, func(format func(subContext formatter.SubContext) error) error { for _, p := range plugins { - pluginCtx := &pluginContext{trunc: fmtCtx.Trunc, p: *p} - if err := format(pluginCtx); err != nil { + if err := format(&pluginContext{ + trunc: fmtCtx.Trunc, + p: *p, + }); err != nil { return err } } return nil - } - pluginCtx := pluginContext{} - pluginCtx.Header = formatter.SubHeaderContext{ - "ID": pluginIDHeader, - "Name": formatter.NameHeader, - "Description": formatter.DescriptionHeader, - "Enabled": enabledHeader, - "PluginReference": formatter.ImageHeader, - } - return fmtCtx.Write(&pluginCtx, render) + }) } type pluginContext struct { From 863b5633f32b98b4ec2df0a6c957a0ca04c02ef2 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 21 Aug 2025 14:48:51 +0200 Subject: [PATCH 07/11] cli/command/registry: inline vars and use struct literals Signed-off-by: Sebastiaan van Stijn --- cli/command/registry/formatter_search.go | 28 ++++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/cli/command/registry/formatter_search.go b/cli/command/registry/formatter_search.go index 3a7cb187b..7fca99b0a 100644 --- a/cli/command/registry/formatter_search.go +++ b/cli/command/registry/formatter_search.go @@ -41,23 +41,27 @@ func SearchWrite(fmtCtx formatter.Context, results []registrytypes.SearchResult) // formatWrite writes the context. func formatWrite(fmtCtx formatter.Context, results []registrytypes.SearchResult) error { - render := func(format func(subContext formatter.SubContext) error) error { + searchCtx := &searchContext{ + HeaderContext: formatter.HeaderContext{ + Header: formatter.SubHeaderContext{ + "Name": formatter.NameHeader, + "Description": formatter.DescriptionHeader, + "StarCount": starsHeader, + "IsOfficial": officialHeader, + }, + }, + } + return fmtCtx.Write(searchCtx, func(format func(subContext formatter.SubContext) error) error { for _, result := range results { - searchCtx := &searchContext{trunc: fmtCtx.Trunc, s: result} - if err := format(searchCtx); err != nil { + if err := format(&searchContext{ + trunc: fmtCtx.Trunc, + s: result, + }); err != nil { return err } } return nil - } - searchCtx := searchContext{} - searchCtx.Header = formatter.SubHeaderContext{ - "Name": formatter.NameHeader, - "Description": formatter.DescriptionHeader, - "StarCount": starsHeader, - "IsOfficial": officialHeader, - } - return fmtCtx.Write(&searchCtx, render) + }) } type searchContext struct { From 12d30bb50c69107e75c5b4481b091be378b66501 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 21 Aug 2025 14:53:50 +0200 Subject: [PATCH 08/11] cli/command/secret: inline vars and use struct literals Signed-off-by: Sebastiaan van Stijn --- cli/command/secret/formatter.go | 36 +++++++++++++++------------------ 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/cli/command/secret/formatter.go b/cli/command/secret/formatter.go index 101c4dddb..2ea29183c 100644 --- a/cli/command/secret/formatter.go +++ b/cli/command/secret/formatter.go @@ -58,7 +58,19 @@ func FormatWrite(fmtCtx formatter.Context, secrets []swarm.Secret) error { // formatWrite writes the context func formatWrite(fmtCtx formatter.Context, secrets []swarm.Secret) error { - render := func(format func(subContext formatter.SubContext) error) error { + sCtx := &secretContext{ + HeaderContext: formatter.HeaderContext{ + Header: formatter.SubHeaderContext{ + "ID": secretIDHeader, + "Name": formatter.NameHeader, + "Driver": formatter.DriverHeader, + "CreatedAt": secretCreatedHeader, + "UpdatedAt": secretUpdatedHeader, + "Labels": formatter.LabelsHeader, + }, + }, + } + return fmtCtx.Write(sCtx, func(format func(subContext formatter.SubContext) error) error { for _, secret := range secrets { secretCtx := &secretContext{s: secret} if err := format(secretCtx); err != nil { @@ -66,22 +78,7 @@ func formatWrite(fmtCtx formatter.Context, secrets []swarm.Secret) error { } } return nil - } - return fmtCtx.Write(newSecretContext(), render) -} - -func newSecretContext() *secretContext { - sCtx := &secretContext{} - - sCtx.Header = formatter.SubHeaderContext{ - "ID": secretIDHeader, - "Name": formatter.NameHeader, - "Driver": formatter.DriverHeader, - "CreatedAt": secretCreatedHeader, - "UpdatedAt": secretUpdatedHeader, - "Labels": formatter.LabelsHeader, - } - return sCtx + }) } type secretContext struct { @@ -147,7 +144,7 @@ func inspectFormatWrite(fmtCtx formatter.Context, refs []string, getRef inspect. if fmtCtx.Format != secretInspectPrettyTemplate { return inspect.Inspect(fmtCtx.Output, refs, string(fmtCtx.Format), getRef) } - render := func(format func(subContext formatter.SubContext) error) error { + return fmtCtx.Write(&secretInspectContext{}, func(format func(subContext formatter.SubContext) error) error { for _, ref := range refs { secretI, _, err := getRef(ref) if err != nil { @@ -162,8 +159,7 @@ func inspectFormatWrite(fmtCtx formatter.Context, refs []string, getRef inspect. } } return nil - } - return fmtCtx.Write(&secretInspectContext{}, render) + }) } type secretInspectContext struct { From e3080364400ae1ef5f9b736d3ce11ef35d119e4c Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 21 Aug 2025 15:00:05 +0200 Subject: [PATCH 09/11] cli/command/service: inline vars and use struct literals Signed-off-by: Sebastiaan van Stijn --- cli/command/service/formatter.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cli/command/service/formatter.go b/cli/command/service/formatter.go index 5cf62efb1..de33fd0c7 100644 --- a/cli/command/service/formatter.go +++ b/cli/command/service/formatter.go @@ -236,7 +236,8 @@ func inspectFormatWrite(fmtCtx formatter.Context, refs []string, getRef, getNetw if fmtCtx.Format != serviceInspectPrettyTemplate { return inspect.Inspect(fmtCtx.Output, refs, string(fmtCtx.Format), getRef) } - render := func(format func(subContext formatter.SubContext) error) error { + + return fmtCtx.Write(&serviceInspectContext{}, func(format func(subContext formatter.SubContext) error) error { for _, ref := range refs { serviceI, _, err := getRef(ref) if err != nil { @@ -246,13 +247,15 @@ func inspectFormatWrite(fmtCtx formatter.Context, refs []string, getRef, getNetw if !ok { return errors.Errorf("got wrong object to inspect") } - if err := format(&serviceInspectContext{Service: service, networkNames: resolveNetworks(service, getNetwork)}); err != nil { + if err := format(&serviceInspectContext{ + Service: service, + networkNames: resolveNetworks(service, getNetwork), + }); err != nil { return err } } return nil - } - return fmtCtx.Write(&serviceInspectContext{}, render) + }) } type serviceInspectContext struct { From 6de2cdd1af6e548721febd05ac8d4f4c54527bbb Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 21 Aug 2025 15:11:15 +0200 Subject: [PATCH 10/11] cli/command/task: inline vars and use struct literals Signed-off-by: Sebastiaan van Stijn --- cli/command/task/formatter.go | 38 ++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/cli/command/task/formatter.go b/cli/command/task/formatter.go index 7f754e8d9..ebf52ee07 100644 --- a/cli/command/task/formatter.go +++ b/cli/command/task/formatter.go @@ -55,27 +55,33 @@ func FormatWrite(fmtCtx formatter.Context, tasks []swarm.Task, names map[string] // formatWrite writes the context. func formatWrite(fmtCtx formatter.Context, tasks []swarm.Task, names map[string]string, nodes map[string]string) error { - render := func(format func(subContext formatter.SubContext) error) error { + taskCtx := &taskContext{ + HeaderContext: formatter.HeaderContext{ + Header: formatter.SubHeaderContext{ + "ID": taskIDHeader, + "Name": formatter.NameHeader, + "Image": formatter.ImageHeader, + "Node": nodeHeader, + "DesiredState": desiredStateHeader, + "CurrentState": currentStateHeader, + "Error": formatter.ErrorHeader, + "Ports": formatter.PortsHeader, + }, + }, + } + return fmtCtx.Write(taskCtx, func(format func(subContext formatter.SubContext) error) error { for _, task := range tasks { - taskCtx := &taskContext{trunc: fmtCtx.Trunc, task: task, name: names[task.ID], node: nodes[task.ID]} - if err := format(taskCtx); err != nil { + if err := format(&taskContext{ + trunc: fmtCtx.Trunc, + task: task, + name: names[task.ID], + node: nodes[task.ID], + }); err != nil { return err } } return nil - } - taskCtx := taskContext{} - taskCtx.Header = formatter.SubHeaderContext{ - "ID": taskIDHeader, - "Name": formatter.NameHeader, - "Image": formatter.ImageHeader, - "Node": nodeHeader, - "DesiredState": desiredStateHeader, - "CurrentState": currentStateHeader, - "Error": formatter.ErrorHeader, - "Ports": formatter.PortsHeader, - } - return fmtCtx.Write(&taskCtx, render) + }) } type taskContext struct { From f72ec26693aa28d3207ea37c29a46238e9c9eec5 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 21 Aug 2025 15:24:18 +0200 Subject: [PATCH 11/11] cli/command/trust: inline vars and use struct literals Signed-off-by: Sebastiaan van Stijn --- cli/command/trust/formatter.go | 42 +++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/cli/command/trust/formatter.go b/cli/command/trust/formatter.go index e536995fd..980636603 100644 --- a/cli/command/trust/formatter.go +++ b/cli/command/trust/formatter.go @@ -73,21 +73,23 @@ func TagWrite(fmtCtx formatter.Context, signedTagInfoList []signedTagInfo) error // tagWrite writes the context func tagWrite(fmtCtx formatter.Context, signedTagInfoList []signedTagInfo) error { - render := func(format func(subContext formatter.SubContext) error) error { + trustTagCtx := &trustTagContext{ + HeaderContext: formatter.HeaderContext{ + Header: formatter.SubHeaderContext{ + "SignedTag": signedTagNameHeader, + "Digest": trustedDigestHeader, + "Signers": signersHeader, + }, + }, + } + return fmtCtx.Write(trustTagCtx, func(format func(subContext formatter.SubContext) error) error { for _, signedTag := range signedTagInfoList { if err := format(&trustTagContext{s: signedTag}); err != nil { return err } } return nil - } - trustTagCtx := trustTagContext{} - trustTagCtx.Header = formatter.SubHeaderContext{ - "SignedTag": signedTagNameHeader, - "Digest": trustedDigestHeader, - "Signers": signersHeader, - } - return fmtCtx.Write(&trustTagCtx, render) + }) } type trustTagContext struct { @@ -120,23 +122,25 @@ func SignerInfoWrite(fmtCtx formatter.Context, signerInfoList []signerInfo) erro // signerInfoWrite writes the context. func signerInfoWrite(fmtCtx formatter.Context, signerInfoList []signerInfo) error { - render := func(format func(subContext formatter.SubContext) error) error { - for _, signerInfo := range signerInfoList { + signerInfoCtx := &signerInfoContext{ + HeaderContext: formatter.HeaderContext{ + Header: formatter.SubHeaderContext{ + "Signer": signerNameHeader, + "Keys": keysHeader, + }, + }, + } + return fmtCtx.Write(signerInfoCtx, func(format func(subContext formatter.SubContext) error) error { + for _, info := range signerInfoList { if err := format(&signerInfoContext{ trunc: fmtCtx.Trunc, - s: signerInfo, + s: info, }); err != nil { return err } } return nil - } - signerInfoCtx := signerInfoContext{} - signerInfoCtx.Header = formatter.SubHeaderContext{ - "Signer": signerNameHeader, - "Keys": keysHeader, - } - return fmtCtx.Write(&signerInfoCtx, render) + }) } type signerInfoContext struct {