-
Notifications
You must be signed in to change notification settings - Fork 111
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
Added method to allow custom RPC commands #11
Changes from all commits
2443d95
e643743
0fbffd8
ab10830
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"bytes" | ||
"encoding/xml" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type RPCMessage struct { | ||
|
@@ -54,7 +55,7 @@ type RPCError struct { | |
} | ||
|
||
func (re *RPCError) Error() string { | ||
return fmt.Sprintf("netconf rpc [%s] '%s'", re.Severity, re.Message) | ||
return fmt.Sprintf("netconf rpc [%s]: %s", re.Severity, strings.Trim(re.Message, "[\r\n]")) | ||
} | ||
|
||
type RPCMethod interface { | ||
|
@@ -78,3 +79,8 @@ func MethodUnlock(target string) RawMethod { | |
func MethodGetConfig(source string) RawMethod { | ||
return RawMethod(fmt.Sprintf("<get-config><source><%s/></source></get-config>", source)) | ||
} | ||
|
||
// RawRPC allows any RPC command to be run on the target. | ||
func RawRPC(command string) RawMethod { | ||
return RawMethod(fmt.Sprintf("%s", command)) | ||
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. Why are you using fmt.Sprintf() here? command can only ever be a string and you're not doing any variable interpolation. 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. That's my bad, I should change that to just reflect |
||
} |
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.
Can you please show me some cases where you need to remove leading and trailing "[\r\n]"?
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.
@charl @scottdware I've just run into the trailing [\n] on some RawMethod output
Using spew, I can see raw output like this
Text: (string) (len=16) "\nAvailable port\n"
I'm not sure where the [\n] is getting introduced. Go1.7.3 xml package
Here is an example code and output