Skip to content
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

cmd: use omitzero option for time.Time #69905

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions src/cmd/go/internal/cache/prog.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ type ProgResponse struct {

// For Get requests.

Miss bool `json:",omitempty"` // cache miss
OutputID []byte `json:",omitempty"`
Size int64 `json:",omitempty"` // in bytes
Time *time.Time `json:",omitempty"` // an Entry.Time; when the object was added to the docs
Miss bool `json:",omitempty"` // cache miss
OutputID []byte `json:",omitempty"`
Size int64 `json:",omitempty"` // in bytes
Time time.Time `json:",omitzero"` // an Entry.Time; when the object was added to the docs

// DiskPath is the absolute path on disk of the ObjectID corresponding
// a "get" request's ActionID (on cache hit) or a "put" request's
Expand Down Expand Up @@ -339,8 +339,8 @@ func (c *ProgCache) Get(a ActionID) (Entry, error) {
e := Entry{
Size: res.Size,
}
if res.Time != nil {
e.Time = *res.Time
if !res.Time.IsZero() {
e.Time = res.Time
} else {
e.Time = time.Now()
}
Expand Down
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 @@ -173,9 +173,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 @@ -387,8 +387,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