-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return role info for each role on pathRoleList #3532
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,3 +110,18 @@ func ListResponse(keys []string) *Response { | |
} | ||
return resp | ||
} | ||
|
||
// ListResponseWithInfo is used to format a response to a list operation and | ||
// return the keys as well as a map with corresponding key info. | ||
func ListResponseWithInfo(keys []string, keyInfo map[string]interface{}) *Response { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooh interesting. |
||
resp := ListResponse(keys) | ||
|
||
resp.Data["key_info"] = map[string]interface{}{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should create the map separately and assign to resp.Data at the end of the response. This avoids having to keep type asserting in the loop...cleaner and faster! Separately, I'm not sure whether, if there are no actual keys, we should return an empty map, a null value, or not add the key at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went with not returning "key_info" at all if it's empty, similar to the behavior with "keys". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. |
||
for _, key := range keys { | ||
val, ok := keyInfo[key] | ||
if ok { | ||
resp.Data["key_info"].(map[string]interface{})[key] = val | ||
} | ||
} | ||
return resp | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intended to ensure that this method doesn't return a nil? If not, the implicit
make
here can be avoided.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea since we are assigning whole
result
map in the switch statement, we don't have to initialize it right away.