ooni-probe-cli/internal/engine/experiment/websteps/control.go
2022-01-05 17:17:20 +01:00

28 lines
838 B
Go

package websteps
import (
"context"
errorsxlegacy "github.com/ooni/probe-cli/v3/internal/engine/legacy/errorsx"
"github.com/ooni/probe-cli/v3/internal/httpx"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
// 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.APIClientTemplate{
BaseURL: thAddr,
HTTPClient: sess.DefaultHTTPClient(),
Logger: sess.Logger(),
}
// make sure error is wrapped
err = errorsxlegacy.SafeErrWrapperBuilder{
Error: clnt.WithBodyLogging().Build().PostJSON(ctx, resourcePath, creq, &out),
Operation: netxlite.TopLevelOperation,
}.MaybeBuild()
return
}