-
Notifications
You must be signed in to change notification settings - Fork 275
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
monitor: add modification functionality #764
Conversation
closes gopcua#710 Signed-off-by: Jack Chen <[email protected]>
|
||
var toModify Item | ||
toModifyReq := make([]*ua.MonitoredItemModifyRequest, 0) | ||
for _, node := range nodes { |
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.
This doesn't look right since something is appended when there was no match or am I missing something here? Also what happens when node.MonitoringParameters
is nil
? That also looks off.
Some minor style comments:
- You don't have to allocate an empty array in Go
- It's a common pattern to use early returns or continues as pre-conditions
- Prefer
req
overrequest
since you're also usingresp
instead ofresponse
How about this?
var modifiedItems[]*ua.MonitoredItemModifyRequest
for _, node := range nodes {
for _, item := range s.itemLookup {
if item.nodeID.String() != node.NodeID.String() {
continue
}
// todo(fs): what happens if node.MonitoringParameters is nil?
// todo(fs): Should the request still be added?
// todo(fs): If not, it could look like this
//
// if node.MonitoringParameters == nil {
// break
// }
// req := &ua.MonitoredItemModifyRequest{
// MonitoredItemID: item.id,
// RequestedParameters: node.MonitoringParameters,
// }
// req.RequestedParameters.ClientHandle = item.handle
// modifiedItems = append(modifiedItems, req)
// break
req := &ua.MonitoredItemModifyRequest{
MonitoredItemID: item.id,
}
if node.MonitoringParameters != nil {
req.RequestedParameters = node.MonitoringParameters
req.RequestedParameters.ClientHandle = item.handle
}
modifiedItems = append(modifiedItems, req)
break
}
}
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.
You're right, using continue
as pre-condition looks much better.
As for other styles, they are actually copied from the existing code (AddMonitorItems). Should I fix them as well in this PR?
I also agree that the request without node.MonitoringParameters
should not be added. Thanks for the suggestion.
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.
As for other styles, they are actually copied from the existing code (AddMonitorItems). Should I fix them as well in this PR?
You're right. I didn't check the rest of the code. Consistency is more important. Keep them as you had it and just fix the pre-condition and the skip of the empty params. Thank you.
Signed-off-by: Jack Chen <[email protected]>
@jackchenjc Thank you! I've merged it and released v0.6.5 |
closes #710