Add envelope.NewAction.
This commit is contained in:
parent
c43feb1f5a
commit
22e29aa8ba
@ -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 {
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user