From 22e29aa8bae39e17a38ec578bb1318677e56b28b Mon Sep 17 00:00:00 2001 From: John Beisley Date: Sat, 26 Mar 2022 10:29:10 +0000 Subject: [PATCH] Add envelope.NewAction. --- v2alpha/soap/envelope/envelope.go | 9 +++++++++ v2alpha/soap/envelope/envelope_test.go | 11 ++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/v2alpha/soap/envelope/envelope.go b/v2alpha/soap/envelope/envelope.go index 05e60ed..7763b56 100644 --- a/v2alpha/soap/envelope/envelope.go +++ b/v2alpha/soap/envelope/envelope.go @@ -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 { diff --git a/v2alpha/soap/envelope/envelope_test.go b/v2alpha/soap/envelope/envelope_test.go index b2fa27d..2198c3f 100644 --- a/v2alpha/soap/envelope/envelope_test.go +++ b/v2alpha/soap/envelope/envelope_test.go @@ -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)