Add envelope.NewAction.

This commit is contained in:
John Beisley 2022-03-26 10:29:10 +00:00
parent c43feb1f5a
commit 22e29aa8ba
2 changed files with 13 additions and 7 deletions

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 {

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{
Foo: "foo-1",
Bar: "bar-2",
},
}
sendAction := NewAction("http://example.com/namespace", "MyAction", &Args{
Foo: "foo-1",
Bar: "bar-2",
})
buf := &bytes.Buffer{}
err := Write(buf, sendAction)