Skip to content

Commit a040a7e

Browse files
committed
fix: drop all omitzero tags — omitempty on structs was always a no-op
The original omitempty on struct-typed fields (time.Time, PostInfo, UserDetailEntry) was a no-op in encoding/json, so zero values were always serialised. Replacing with omitzero would change actual behaviour by omitting these fields when zero-valued, breaking API responses and RPC wire format. Just drop the tag entirely to preserve existing behaviour.
1 parent 4d0d43b commit a040a7e

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed

backend/app/cmd/cleanup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (cc *CleanupCommand) listComments(postURL string) ([]store.Comment, error)
179179

180180
commentsWithInfo := struct {
181181
Comments []store.Comment `json:"comments"`
182-
Info store.PostInfo `json:"info,omitzero"`
182+
Info store.PostInfo `json:"info"`
183183
}{}
184184

185185
if err = json.NewDecoder(r.Body).Decode(&commentsWithInfo); err != nil {

backend/app/cmd/cleanup_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func cleanupRoutes(t *testing.T, r *chi.Mux, c *cleanedComments) {
173173

174174
commentsWithInfo := struct {
175175
Comments []store.Comment `json:"comments"`
176-
Info store.PostInfo `json:"info,omitzero"`
176+
Info store.PostInfo `json:"info"`
177177
}{}
178178

179179
switch r.URL.Query().Get("url") {

backend/app/migrator/commento.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type commentoCommenter struct {
4848
Link string `json:"link"`
4949
Photo string `json:"photo"`
5050
Provider string `json:"provider,omitempty"`
51-
JoinDate time.Time `json:"joinDate,omitzero"`
51+
JoinDate time.Time `json:"joinDate"`
5252
IsModerator bool `json:"isModerator"`
5353
}
5454

backend/app/rest/api/rest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ const lastCommentsScope = "last"
9696

9797
type commentsWithInfo struct {
9898
Comments []store.Comment `json:"comments"`
99-
Info store.PostInfo `json:"info,omitzero"`
99+
Info store.PostInfo `json:"info"`
100100
}
101101

102102
type treeWithInfo struct {
103103
*service.Tree
104-
Info store.PostInfo `json:"info,omitzero"`
104+
Info store.PostInfo `json:"info"`
105105
}
106106

107107
// Run the lister and request's router, activate rest server

backend/app/store/comment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ type PostInfo struct {
5050
CountLeft int `json:"count_left"` // used only with returning search results limited by number, otherwise zero
5151
LastComment string `json:"last_comment,omitempty"` // used only with returning search results limited by number
5252
ReadOnly bool `json:"read_only,omitempty" bson:"read_only,omitempty"` // can be attached to site-wide comments but won't be set then
53-
FirstTS time.Time `json:"first_time,omitzero" bson:"first_time,omitempty"`
54-
LastTS time.Time `json:"last_time,omitzero" bson:"last_time,omitempty"`
53+
FirstTS time.Time `json:"first_time" bson:"first_time,omitempty"`
54+
LastTS time.Time `json:"last_time" bson:"last_time,omitempty"`
5555
}
5656

5757
// BlockedUser holds id and ts for blocked user

backend/app/store/service/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type UserMetaData struct {
6262
Until time.Time `json:"until"`
6363
} `json:"blocked"`
6464
Verified bool `json:"verified"`
65-
Details engine.UserDetailEntry `json:"details,omitzero"`
65+
Details engine.UserDetailEntry `json:"details"`
6666
}
6767

6868
// PostMetaData keeps info about post flags

0 commit comments

Comments
 (0)