ChrisHines commented on a change in pull request #3996: Rewrote /user/current 
to Go
URL: https://github.com/apache/trafficcontrol/pull/3996#discussion_r341705696
 
 

 ##########
 File path: lib/go-tc/users.go
 ##########
 @@ -101,6 +110,179 @@ type UserCurrent struct {
        commonUserFields
 }
 
+// CurrentUserUpdateRequest differs from a regular User/UserCurrent in that 
many of its fields are
+// *parsed* but not *unmarshaled*. This allows a handler to distinguish 
between "null" and
+// "undefined" values.
+type CurrentUserUpdateRequest struct {
+       // User, for whatever reason, contains all of the actual data.
+       User CurrentUserUpdateRequestUser `json:"user"`
+}
+
+// CurrentUserUpdateRequestUser holds all of the actual data in a request to 
update the current user.
+type CurrentUserUpdateRequestUser struct {
+       AddressLine1       json.RawMessage `json:"addressLine1"`
+       AddressLine2       json.RawMessage `json:"addressLine2"`
+       City               json.RawMessage `json:"city"`
+       Company            json.RawMessage `json:"company"`
+       ConfirmLocalPasswd *string         `json:"confirmLocalPasswd"`
+       Country            json.RawMessage `json:"country"`
+       Email              json.RawMessage `json:"email"`
+       FullName           json.RawMessage `json:"fullName"`
+       GID                json.RawMessage `json:"gid"`
+       ID                 json.RawMessage `json:"id"`
+       LocalPasswd        *string         `json:"localPasswd"`
+       PhoneNumber        json.RawMessage `json:"phoneNumber"`
+       PostalCode         json.RawMessage `json:"postalCode"`
+       PublicSSHKey       json.RawMessage `json:"publicSshKey"`
+       Role               json.RawMessage `json:"role"`
+       StateOrProvince    json.RawMessage `json:"stateOrProvince"`
+       TenantID           json.RawMessage `json:"tenantId"`
+       UID                json.RawMessage `json:"uid"`
+       Username           json.RawMessage `json:"username"`
+}
+
+// ValidateAndUnmarshal validates the request and returns a User into which 
the request's information
+// has been unmarshalled. This allows many fields to be "null", but explicitly 
checks that they are
+// present in the JSON payload.
+func (u *CurrentUserUpdateRequestUser) ValidateAndUnmarshal(user *User) error {
 
 Review comment:
   Ignore this if it bucks an existing convention I am not aware of.
   
   Consider wether the name `UnmarshalAndValidate` does a better job conveying 
the order of operations this method performs.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to