ooni-probe-cli/internal/engine/experiment/websteps/control.go
Simone Basso ee78c76085
refactor: i/errorsx is now i/legacy/errorsx (#479)
We need still to add similar wrappers to internal/netxlite but we
will adopt a saner approach to error wrapping this time.

See https://github.com/ooni/probe/issues/1591
2021-09-07 17:52:42 +02:00

28 lines
821 B
Go

package websteps
import (
"context"
"github.com/ooni/probe-cli/v3/internal/engine/httpx"
errorsxlegacy "github.com/ooni/probe-cli/v3/internal/engine/legacy/errorsx"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
)
// Control performs the control request and returns the response.
func Control(
ctx context.Context, sess model.ExperimentSession,
thAddr string, resourcePath string, creq CtrlRequest) (out CtrlResponse, err error) {
clnt := httpx.Client{
BaseURL: thAddr,
HTTPClient: sess.DefaultHTTPClient(),
Logger: sess.Logger(),
}
// make sure error is wrapped
err = errorsxlegacy.SafeErrWrapperBuilder{
Error: clnt.PostJSON(ctx, resourcePath, creq, &out),
Operation: errorsx.TopLevelOperation,
}.MaybeBuild()
return
}