Add envelope.NewAction.

This commit is contained in:
John Beisley committed 2022-03-26 10:29:10 +00:00
1 parent c43feb1f5a
commit 22e29aa8ba
2 files changed
+11 -5

No files matched your search

+9
View File
@@ -55,6 +55,15 @@ type Action struct {
Args any `xml:",any"`
}
// NewAction creates a SOAP action for sending with the given namespace URL,
// action name, and arguments.
func NewAction(nsURL, actionName string, args any) *Action {
return &Action{
XMLName: xml.Name{Space: nsURL, Local: actionName},
Args: args,
}
}
// Write marshals a SOAP envelope to the writer. Errors can be from the writer
// or XML encoding.
func Write(w io.Writer, action *Action) error {
+2 -5
View File
@@ -16,13 +16,10 @@ func TestWriteRead(t *testing.T) {
Bar string `xml:"bar"`
}
sendAction := &Action{
XMLName: xml.Name{Space: "http://example.com/namespace", Local: "MyAction"},
Args: &Args{
sendAction := NewAction("http://example.com/namespace", "MyAction", &Args{
Foo: "foo-1",
Bar: "bar-2",
},
}
})
buf := &bytes.Buffer{}
err := Write(buf, sendAction)