Rearrange Client.as a helper function.
This narrows the API surface of the `Client` type.
This commit is contained in:
parent
ca91893cc0
commit
5d0813cf55
@ -57,21 +57,6 @@ func New(endpointURL string, opts ...Option) *Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PerformAction makes a SOAP request, with the given `argsIn` as input
|
|
||||||
// arguments, and `argsOut` to capture the output arguments into.
|
|
||||||
// `serviceType` is the SOAP service type URN, `actionName` is the action to
|
|
||||||
// call.
|
|
||||||
//
|
|
||||||
// This is a convenience for calling `c.Do` without creating `*Action` values.
|
|
||||||
func (c *Client) PerformAction(
|
|
||||||
ctx context.Context, serviceType, actionName string,
|
|
||||||
argsIn, argsOut any,
|
|
||||||
) error {
|
|
||||||
actionIn := envelope.NewSendAction(serviceType, actionName, argsIn)
|
|
||||||
actionOut := &envelope.Action{Args: argsOut}
|
|
||||||
return c.Do(ctx, actionIn, actionOut)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PerformAction makes a SOAP request, with the given action values to provide
|
// PerformAction makes a SOAP request, with the given action values to provide
|
||||||
// arguments (`args`) and capture the `reply` into.
|
// arguments (`args`) and capture the `reply` into.
|
||||||
func (c *Client) Do(
|
func (c *Client) Do(
|
||||||
@ -100,6 +85,22 @@ func (c *Client) Do(
|
|||||||
return ParseResponseAction(resp, actionOut)
|
return ParseResponseAction(resp, actionOut)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PerformAction makes a SOAP request, with the given `argsIn` as input
|
||||||
|
// arguments, and `argsOut` to capture the output arguments into.
|
||||||
|
// `serviceType` is the SOAP service type URN, `actionName` is the action to
|
||||||
|
// call.
|
||||||
|
//
|
||||||
|
// This is a convenience for calling `Client.Do` without creating `*Action` values.
|
||||||
|
func PerformAction(
|
||||||
|
ctx context.Context, c *Client,
|
||||||
|
serviceType, actionName string,
|
||||||
|
argsIn, argsOut any,
|
||||||
|
) error {
|
||||||
|
actionIn := envelope.NewSendAction(serviceType, actionName, argsIn)
|
||||||
|
actionOut := &envelope.Action{Args: argsOut}
|
||||||
|
return c.Do(ctx, actionIn, actionOut)
|
||||||
|
}
|
||||||
|
|
||||||
// SetRequestAction updates fields in `req` with the given SOAP action.
|
// SetRequestAction updates fields in `req` with the given SOAP action.
|
||||||
// Specifically it sets Body, ContentLength, Method, and the SOAPACTION and
|
// Specifically it sets Body, ContentLength, Method, and the SOAPACTION and
|
||||||
// CONTENT-TYPE headers.
|
// CONTENT-TYPE headers.
|
||||||
|
@ -75,7 +75,7 @@ func (fss *fakeSoapServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDo(t *testing.T) {
|
func TestPerformAction(t *testing.T) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
t.Cleanup(cancel)
|
t.Cleanup(cancel)
|
||||||
|
|
||||||
@ -91,12 +91,10 @@ func TestDo(t *testing.T) {
|
|||||||
|
|
||||||
c := New(ts.URL + "/endpointpath")
|
c := New(ts.URL + "/endpointpath")
|
||||||
|
|
||||||
reqAction := envelope.NewSendAction("http://example.com/endpointns", "Foo",
|
|
||||||
&ActionArgs{Name: "World"})
|
|
||||||
reply := &ActionReply{}
|
reply := &ActionReply{}
|
||||||
replyAction := &envelope.Action{Args: reply}
|
|
||||||
|
|
||||||
if err := c.Do(ctx, reqAction, replyAction); err != nil {
|
if err := PerformAction(ctx, c, "http://example.com/endpointns", "Foo",
|
||||||
|
&ActionArgs{Name: "World"}, reply); err != nil {
|
||||||
t.Errorf("got error: %v, want success", err)
|
t.Errorf("got error: %v, want success", err)
|
||||||
} else {
|
} else {
|
||||||
if got, want := reply.Greeting, "Hello, World!"; got != want {
|
if got, want := reply.Greeting, "Hello, World!"; got != want {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user