Skip to content

Commit 314e30b

Browse files
committed
fix: F1008: could remove embedded field (staticcheck)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 4116019 commit 314e30b

2 files changed

Lines changed: 28 additions & 28 deletions

File tree

commands/history/ls.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const (
3333
lsHeaderDuration = "DURATION"
3434
lsHeaderLink = ""
3535

36-
lsDefaultTableFormat = "table {{.Ref}}\t{{.Name}}\t{{.Status}}\t{{.CreatedAt}}\t{{.Duration}}\t{{.Link}}"
36+
lsDefaultTableFormat = "table {{.BuildID}}\t{{.Name}}\t{{.Status}}\t{{.Created}}\t{{.Duration}}\t{{.Link}}"
3737

3838
headerKeyTimestamp = "buildkit-current-timestamp"
3939
)
@@ -87,7 +87,7 @@ func runLs(ctx context.Context, dockerCli command.Cli, opts lsOptions) error {
8787

8888
for i, rec := range out {
8989
st, _ := ls.ReadRef(rec.node.Builder, rec.node.Name, rec.Ref)
90-
rec.Name = historyutil.BuildName(rec.FrontendAttrs, st)
90+
rec.name = historyutil.BuildName(rec.FrontendAttrs, st)
9191
out[i] = rec
9292
}
9393

@@ -162,12 +162,12 @@ func lsPrint(dockerCli command.Cli, records []historyRecord, in lsOptions) error
162162
trunc: !in.noTrunc,
163163
}
164164
lsCtx.Header = formatter.SubHeaderContext{
165-
"Ref": lsHeaderBuildID,
166-
"Name": lsHeaderName,
167-
"Status": lsHeaderStatus,
168-
"CreatedAt": lsHeaderCreated,
169-
"Duration": lsHeaderDuration,
170-
"Link": lsHeaderLink,
165+
"BuildID": lsHeaderBuildID,
166+
"Name": lsHeaderName,
167+
"Status": lsHeaderStatus,
168+
"Created": lsHeaderCreated,
169+
"Duration": lsHeaderDuration,
170+
"Link": lsHeaderLink,
171171
}
172172

173173
return ctx.Write(&lsCtx, render)
@@ -187,58 +187,58 @@ func (c *lsContext) MarshalJSON() ([]byte, error) {
187187
"ref": c.FullRef(),
188188
"name": c.Name(),
189189
"status": c.Status(),
190-
"created_at": c.historyRecord.CreatedAt.AsTime().Format(time.RFC3339Nano),
191-
"total_steps": c.historyRecord.NumTotalSteps,
192-
"completed_steps": c.historyRecord.NumCompletedSteps,
193-
"cached_steps": c.historyRecord.NumCachedSteps,
190+
"created_at": c.CreatedAt.AsTime().Format(time.RFC3339Nano),
191+
"total_steps": c.NumTotalSteps,
192+
"completed_steps": c.NumCompletedSteps,
193+
"cached_steps": c.NumCachedSteps,
194194
}
195-
if c.historyRecord.CompletedAt != nil {
196-
m["completed_at"] = c.historyRecord.CompletedAt.AsTime().Format(time.RFC3339Nano)
195+
if c.CompletedAt != nil {
196+
m["completed_at"] = c.CompletedAt.AsTime().Format(time.RFC3339Nano)
197197
}
198198
return json.Marshal(m)
199199
}
200200

201-
func (c *lsContext) Ref() string {
202-
return c.historyRecord.Ref
201+
func (c *lsContext) BuildID() string {
202+
return c.Ref
203203
}
204204

205205
func (c *lsContext) FullRef() string {
206-
return fmt.Sprintf("%s/%s/%s", c.historyRecord.node.Builder, c.historyRecord.node.Name, c.historyRecord.Ref)
206+
return fmt.Sprintf("%s/%s/%s", c.node.Builder, c.node.Name, c.Ref)
207207
}
208208

209209
func (c *lsContext) Name() string {
210-
name := c.historyRecord.Name
210+
name := c.name
211211
if c.trunc && c.format.IsTable() {
212212
return trimBeginning(name, 36)
213213
}
214214
return name
215215
}
216216

217217
func (c *lsContext) Status() string {
218-
if c.historyRecord.CompletedAt != nil {
219-
if c.historyRecord.Error != nil {
218+
if c.CompletedAt != nil {
219+
if c.Error != nil {
220220
return "Error"
221221
}
222222
return "Completed"
223223
}
224224
return "Running"
225225
}
226226

227-
func (c *lsContext) CreatedAt() string {
228-
return units.HumanDuration(time.Since(c.historyRecord.CreatedAt.AsTime())) + " ago"
227+
func (c *lsContext) Created() string {
228+
return units.HumanDuration(time.Since(c.CreatedAt.AsTime())) + " ago"
229229
}
230230

231231
func (c *lsContext) Duration() string {
232-
lastTime := c.historyRecord.currentTimestamp
233-
if c.historyRecord.CompletedAt != nil {
234-
tm := c.historyRecord.CompletedAt.AsTime()
232+
lastTime := c.currentTimestamp
233+
if c.CompletedAt != nil {
234+
tm := c.CompletedAt.AsTime()
235235
lastTime = &tm
236236
}
237237
if lastTime == nil {
238238
return ""
239239
}
240-
v := formatDuration(lastTime.Sub(c.historyRecord.CreatedAt.AsTime()))
241-
if c.historyRecord.CompletedAt == nil {
240+
v := formatDuration(lastTime.Sub(c.CreatedAt.AsTime()))
241+
if c.CompletedAt == nil {
242242
v += "+"
243243
}
244244
return v

commands/history/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type historyRecord struct {
3333
*controlapi.BuildHistoryRecord
3434
currentTimestamp *time.Time
3535
node *builder.Node
36-
Name string
36+
name string
3737
}
3838

3939
type queryOptions struct {

0 commit comments

Comments
 (0)