I have a struct:
type User struct {
ID int `json:"id"`
Username string `json:"username"`
About string `json:"about"`
IsAdmin bool `json:"is_admin"`
Status int `json:"status"`
......
}
A:= User{1,"admin", "I am a admin",status: 1,....}
B:= User{ID:1, Username: "UserBBBB"}
...enter code here...
B is {1, "UserBBBB", "I am a admin", 1, ...(same value in A)}
object B has a few properties with nil (string), false (bool), 0 (int),... I want to check if a field of B is unassigned value, that field will receive value of the same field in A,
example:
B's About field is nil;
A's About field is "I am a admin" I want to B's About field is "I am a admin".
I can write code:
if len(B.About) == 0 {
B.About = A.About
} Similar to other fields, I don't want check step by step with all of fields.