Skip to content

cmd: use omitzero option for time.Time #69905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cmd/go/internal/modinfo/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type ModulePublic struct {
Query string `json:",omitempty"` // version query corresponding to this version
Versions []string `json:",omitempty"` // available module versions
Replace *ModulePublic `json:",omitempty"` // replaced by this module
Time *time.Time `json:",omitempty"` // time version was created
Time time.Time `json:",omitzero"` // time version was created
Update *ModulePublic `json:",omitempty"` // available update (with -u)
Main bool `json:",omitempty"` // is this the main module?
Indirect bool `json:",omitempty"` // module is only indirectly needed by main module
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/go/internal/modload/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func addUpdate(ctx context.Context, m *modinfo.ModulePublic) {
m.Update = &modinfo.ModulePublic{
Path: m.Path,
Version: info.Version,
Time: &info.Time,
Time: info.Time,
}
}
}
Expand Down Expand Up @@ -344,7 +344,7 @@ func moduleInfo(ctx context.Context, rs *Requirements, m module.Version, mode Li
m.Error = &modinfo.ModuleError{Err: err.Error()}
} else {
m.Version = q.Version
m.Time = &q.Time
m.Time = q.Time
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/cmd/go/internal/modload/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ func queryProxy(ctx context.Context, proxy, path, query, current string, allowed
Version: old.Version,
Origin: old.Origin,
}
if old.Time != nil {
info.Time = *old.Time
if !old.Time.IsZero() {
info.Time = old.Time
}
return info, nil
}
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/go/internal/work/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ type actionJSON struct {
NeedBuild bool `json:",omitempty"`
ActionID string `json:",omitempty"`
BuildID string `json:",omitempty"`
TimeReady time.Time `json:",omitempty"`
TimeStart time.Time `json:",omitempty"`
TimeDone time.Time `json:",omitempty"`
TimeReady time.Time `json:",omitzero"`
TimeStart time.Time `json:",omitzero"`
TimeDone time.Time `json:",omitzero"`

Cmd []string // `json:",omitempty"`
CmdReal time.Duration `json:",omitempty"`
Expand Down
5 changes: 2 additions & 3 deletions src/cmd/internal/test2json/test2json.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (

// event is the JSON struct we emit.
type event struct {
Time *time.Time `json:",omitempty"`
Time time.Time `json:",omitzero"`
Action string
Package string `json:",omitempty"`
Test string `json:",omitempty"`
Expand Down Expand Up @@ -402,8 +402,7 @@ func (c *Converter) writeOutputEvent(out []byte) {
func (c *Converter) writeEvent(e *event) {
e.Package = c.pkg
if c.mode&Timestamp != 0 {
t := time.Now()
e.Time = &t
e.Time = time.Now()
}
if e.Test == "" {
e.Test = c.testName
Expand Down