refactor!: rename Response->Message and remove Response types #114
No reviewers
Labels
No labels
breaking-change
bug
dependencies
duplicate
enhancement
go
good first issue
help wanted
invalid
investigation
proposal
proposal-accepted
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
nemith/netconf!114
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "brb/push-omyxmytmpuxn"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
While working on the new Notification support it was obvious that a Reponse being a stream of the returning object is the same for
<notification>as well as<rpc-reply>' messages.Message` is a much better name for the objects comming from a NETCONF server.So while we are still making some breaking changes lets do it right.
Also with
ResponsegoneRequestis looking very useless. Lets useRPCdirectly.Also added a
(s *Session) Prepare(*RPC) *RPCmethod which will take a bare RPC and make it the exact version that will be sent on the wire (i.d with a message-id if one was missing). This is optional but needed for an upcoming CLI I will be creating.Pull request overview
This PR performs a significant refactoring of the NETCONF library's core messaging types to better support both RPC replies and notifications. The main change renames
ResponsetoMessageto reflect that NETCONF streams can contain both<rpc-reply>and<notification>messages. Additionally, it removes theRequestwrapper type in favor of usingRPCdirectly, and adds aPrepare()method for explicitly preparing RPCs with message IDs.Key changes:
Responsetype toMessagewith encapsulated reader and message-id fieldsSession.Do()to accept*RPCdirectly instead of*Request, with automatic message-id assignmentSession.Prepare()method to explicitly prepare RPCs with message-ids for use cases like CLI toolsReviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@ -28,0 +59,4 @@MessageID: r.MessageID,Attributes: slices.Clone(r.Attributes),Operation: r.Operation,}The Clone method performs a shallow copy of the Operation field. If Operation contains pointers or reference types, modifications to the cloned RPC's Operation will affect the original. Consider documenting this behavior or implementing a deep copy if the Operation field needs to be fully independent
@ -158,3 +199,4 @@type Hello struct {XMLName xml.Name `xml:"urn:ietf:params:xml:ns:netconf:base:1.0 hello"`SessionID uint64 `xml:"session-id,omitempty"`Capabilities []string `xml:"capabilities>capability"`Typo in documentation: "dones't" should be "doesn't"
@ -371,3 +388,4 @@raw, err := io.ReadAll(msg)if err != nil {return fmt.Errorf("failed to read reply: %w", err)}The comment should be updated to reflect that this is a higher-level method compared to the old implementation. It now automatically assigns a message-id if one is missing, which is different behavior from before
The Do method modifies the input parameter
rpcby reassigning it when MessageID is empty. This can be confusing because the modification only affects the local variable, not the caller's copy. Consider one of these approaches:The documentation comment should be updated to reflect the new parameter names. It still refers to
reqandrespbut the parameters are nowopandreply@ -371,3 +388,4 @@raw, err := io.ReadAll(msg)if err != nil {return fmt.Errorf("failed to read reply: %w", err)}No