我有结构:
type TripFeedback struct {
ID primitive.ObjectID `json:"_id" bson:"_id,omitempty"`
UserID string `json:"user_id" bson:"user_id"`
WaybillID uint64 `json:"waybill_id" bson:"waybill_id"`
Rating Rating `json:"rating" bson:"rating"`
Comment string `json:"comment" bson:"comment"`
CreatedAt time.Time `json:"created_at" bson:"created_at"`
}
当我创建一个对象时,它看起来像这样(看时间):
0: {ObjectID("010000000000000000000000") 53566444-4334-11ee-be56-0242ac120002 5 4 2023-08-25 13:44:22.89 +0000 UTC}
1: {ObjectID("020000000000000000000000") 53566444-4334-11ee-be56-0242ac120002 12 4 2023-08-25 13:44:22.89 +0000 UTC}
2: {ObjectID("030000000000000000000000") 53566444-4334-11ee-be56-0242ac120002 51 3 2023-08-25 13:44:22.89 +0000 UTC}
3: {ObjectID("040000000000000000000000") 53566444-4334-11ee-be56-0242ac120002 53 5 2023-08-25 13:44:22.89 +0000 UTC}
4: {ObjectID("050000000000000000000000") 53566444-4334-11ee-be56-0242ac120002 53 5 2023-08-25 13:44:22.89 +0000 UTC}
5: {ObjectID("060000000000000000000000") 53566444-4334-11ee-be56-0242ac120002 54 4 2023-08-25 13:44:22.89 +0000 UTC}
但是当我从 mongodb 收到响应并将其解析为相同的结构时,它看起来像这样:
0: {ObjectID("010000000000000000000000") 53566444-4334-11ee-be56-0242ac120002 5 4 2023-08-25 13:44:22.8902373 +0000 UTC m=+0.005347601}
1: {ObjectID("020000000000000000000000") 53566444-4334-11ee-be56-0242ac120002 12 4 2023-08-25 13:44:22.8902373 +0000 UTC m=+0.005347601}
2: {ObjectID("030000000000000000000000") 53566444-4334-11ee-be56-0242ac120002 51 3 2023-08-25 13:44:22.8902373 +0000 UTC m=+0.005347601}
3: {ObjectID("040000000000000000000000") 53566444-4334-11ee-be56-0242ac120002 53 5 2023-08-25 13:44:22.8902373 +0000 UTC m=+0.005347601}
4: {ObjectID("050000000000000000000000") 53566444-4334-11ee-be56-0242ac120002 53 5 2023-08-25 13:44:22.8902373 +0000 UTC m=+0.005347601}
5: {ObjectID("060000000000000000000000") 53566444-4334-11ee-be56-0242ac120002 54 4 2023-08-25 13:44:22.8902373 +0000 UTC m=+0.005347601}
为什么时间字段不同?怎么处理呢?我的
CreatedAt
不应该是 time.Time
类型吗?(因为至少我必须编写一些测试)。谢谢你
数值相同,可以忽略
m=
部分。 TripFeedback.CreatedAt
属于 time.Time
类型,它不能是任何其他类型,因为 Go 是静态类型语言。