From 5bc467e2ca67c47ecd80b7e7bc7c22fb4f203eed Mon Sep 17 00:00:00 2001 From: Julio Lopez <1953782+julio-lopez@users.noreply.github.com> Date: Thu, 23 Oct 2025 22:59:52 -0700 Subject: [PATCH] refactor(general): `omitzero` JSON tag (#4907) * remove omitempty from object id fields * remove omitempty from storage stats fields * use omitzero for other structs * remove `omitempty` from `UpgradeLockIntent` fields The `omitempty` JSON tag is ineffective for fields of type `Time` and `Duration`. Also, this struct is only used during the "upgrade" protocol, and it is OK to explicitly serialize 0 values, as it was done before. --- repo/blob/rclone/rclone_options.go | 2 +- repo/format/content_format.go | 8 ++++---- repo/format/upgrade_lock_intent.go | 8 ++++---- repo/object/indirect.go | 2 +- snapshot/manifest.go | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/repo/blob/rclone/rclone_options.go b/repo/blob/rclone/rclone_options.go index bd551f88e..f544f833e 100644 --- a/repo/blob/rclone/rclone_options.go +++ b/repo/blob/rclone/rclone_options.go @@ -12,7 +12,7 @@ type Options struct { RCloneExe string `json:"rcloneExe,omitempty"` // path to rclone executable RCloneArgs []string `json:"rcloneArgs,omitempty"` // additional rclone arguments RCloneEnv []string `json:"rcloneEnv,omitempty"` // additional rclone environment variables - StartupTimeout jsonencoding.Duration `json:"startupTimeout,omitempty"` // time to wait for rclone to start + StartupTimeout jsonencoding.Duration `json:"startupTimeout,omitzero"` // time to wait for rclone to start Debug bool `json:"debug,omitempty"` // log rclone output NoWaitForTransfers bool `json:"noWaitForTransfers,omitempty"` // when set to true, don't wait for transfers to finish when closing EmbeddedConfig string `json:"embeddedConfig,omitempty"` diff --git a/repo/format/content_format.go b/repo/format/content_format.go index cb0845fd9..811847c89 100644 --- a/repo/format/content_format.go +++ b/repo/format/content_format.go @@ -63,10 +63,10 @@ func (f *ContentFormat) SupportsPasswordChange() bool { // MutableParameters represents parameters of the content manager that can be mutated after the repository // is created. type MutableParameters struct { - Version Version `json:"version,omitempty"` // version number, must be "1", "2" or "3" - MaxPackSize int `json:"maxPackSize,omitempty"` // maximum size of a pack object - IndexVersion int `json:"indexVersion,omitempty"` // force particular index format version (1,2,..) - EpochParameters epoch.Parameters `json:"epochParameters,omitempty"` // epoch manager parameters + Version Version `json:"version,omitempty"` // version number, must be "1", "2" or "3" + MaxPackSize int `json:"maxPackSize,omitempty"` // maximum size of a pack object + IndexVersion int `json:"indexVersion,omitempty"` // force particular index format version (1,2,..) + EpochParameters epoch.Parameters `json:"epochParameters,omitzero"` // epoch manager parameters } // Validate validates the parameters. diff --git a/repo/format/upgrade_lock_intent.go b/repo/format/upgrade_lock_intent.go index 8b9e9fd9f..56a6be315 100644 --- a/repo/format/upgrade_lock_intent.go +++ b/repo/format/upgrade_lock_intent.go @@ -13,10 +13,10 @@ // repository. type UpgradeLockIntent struct { OwnerID string `json:"ownerID,omitempty"` - CreationTime time.Time `json:"creationTime,omitempty"` - AdvanceNoticeDuration time.Duration `json:"advanceNoticeDuration,omitempty"` - IODrainTimeout time.Duration `json:"ioDrainTimeout,omitempty"` - StatusPollInterval time.Duration `json:"statusPollInterval,omitempty"` + CreationTime time.Time `json:"creationTime"` + AdvanceNoticeDuration time.Duration `json:"advanceNoticeDuration"` + IODrainTimeout time.Duration `json:"ioDrainTimeout"` + StatusPollInterval time.Duration `json:"statusPollInterval"` Message string `json:"message,omitempty"` MaxPermittedClockDrift time.Duration `json:"maxPermittedClockDrift,omitempty"` } diff --git a/repo/object/indirect.go b/repo/object/indirect.go index 252e6c181..48e499ab7 100644 --- a/repo/object/indirect.go +++ b/repo/object/indirect.go @@ -4,7 +4,7 @@ type IndirectObjectEntry struct { Start int64 `json:"s,omitempty"` Length int64 `json:"l,omitempty"` - Object ID `json:"o,omitempty"` + Object ID `json:"o"` } func (i *IndirectObjectEntry) endOffset() int64 { diff --git a/snapshot/manifest.go b/snapshot/manifest.go index 01d6d6381..77f20a284 100644 --- a/snapshot/manifest.go +++ b/snapshot/manifest.go @@ -126,7 +126,7 @@ type DirEntry struct { ModTime fs.UTCTimestamp `json:"mtime,omitempty"` UserID uint32 `json:"uid,omitempty"` GroupID uint32 `json:"gid,omitempty"` - ObjectID object.ID `json:"obj,omitempty"` + ObjectID object.ID `json:"obj"` DirSummary *fs.DirectorySummary `json:"summ,omitempty"` } @@ -187,8 +187,8 @@ func (m *Manifest) Clone() *Manifest { type StorageStats struct { // amount of new unique data in this snapshot that wasn't there before. // note that this depends on ordering of snapshots. - NewData StorageUsageDetails `json:"newData,omitempty"` - RunningTotal StorageUsageDetails `json:"runningTotal,omitempty"` + NewData StorageUsageDetails `json:"newData"` + RunningTotal StorageUsageDetails `json:"runningTotal"` } // StorageUsageDetails provides details about snapshot storage usage.