2e0118d1a6
## Description This PR continues the refactoring of `netx` under the following principles: 1. do not break the rest of the tree and do not engage in extensive tree-wide refactoring yet 2. move under `netxlite` clearly related subpackages (e.g., `iox`, `netxmocks`) 3. move into `internal/netxlite/internal` stuff that is clearly private of `netxlite` 4. hide implementation details in `netxlite` pending new factories 5. refactor `tls` code in `netxlite` to clearly separate `crypto/tls` code from `utls` code After each commit, I run `go test -short -race ./...` locally. Each individual commit explains what it does. I will squash, but this operation will preserve the original commit titles, so this will give further insight on each step. ## Commits * refactor: rename netxmocks -> netxlite/mocks Part of https://github.com/ooni/probe/issues/1591 * refactor: rename quicx -> netxlite/quicx See https://github.com/ooni/probe/issues/1591 * refactor: rename iox -> netxlite/iox Regenerate sources and make sure the tests pass. See https://github.com/ooni/probe/issues/1591. * refactor(iox): move MockableReader to netxlite/mocks See https://github.com/ooni/probe/issues/1591 * refactor(netxlite): generator is an implementation detail See https://github.com/ooni/probe/issues/1591 * refactor(netxlite): separate tls and utls code See https://github.com/ooni/probe/issues/1591 * refactor(netxlite): hide most types but keep old names as legacy With this change we avoid breaking the rest of the tree, but we start hiding some implementation details a bit. Factories will follow. See https://github.com/ooni/probe/issues/1591
278 lines
7.0 KiB
Go
278 lines
7.0 KiB
Go
// Code generated by go generate; DO NOT EDIT.
|
|
// 2021-09-05 13:54:22.556115 +0200 CEST m=+0.000158543
|
|
|
|
package ooapi
|
|
|
|
//go:generate go run ./internal/generator -file responses.go
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite/iox"
|
|
"github.com/ooni/probe-cli/v3/internal/ooapi/apimodel"
|
|
)
|
|
|
|
func (api *simpleCheckReportIDAPI) newResponse(ctx context.Context, resp *http.Response, err error) (*apimodel.CheckReportIDResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := iox.ReadAllContext(ctx, reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.CheckReportIDResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleCheckInAPI) newResponse(ctx context.Context, resp *http.Response, err error) (*apimodel.CheckInResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := iox.ReadAllContext(ctx, reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.CheckInResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleLoginAPI) newResponse(ctx context.Context, resp *http.Response, err error) (*apimodel.LoginResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := iox.ReadAllContext(ctx, reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.LoginResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleMeasurementMetaAPI) newResponse(ctx context.Context, resp *http.Response, err error) (*apimodel.MeasurementMetaResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := iox.ReadAllContext(ctx, reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.MeasurementMetaResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleRegisterAPI) newResponse(ctx context.Context, resp *http.Response, err error) (*apimodel.RegisterResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := iox.ReadAllContext(ctx, reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.RegisterResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleTestHelpersAPI) newResponse(ctx context.Context, resp *http.Response, err error) (apimodel.TestHelpersResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := iox.ReadAllContext(ctx, reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := apimodel.TestHelpersResponse{}
|
|
if err := api.jsonCodec().Decode(data, &out); err != nil {
|
|
return nil, err
|
|
}
|
|
if out == nil {
|
|
return nil, ErrJSONLiteralNull
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simplePsiphonConfigAPI) newResponse(ctx context.Context, resp *http.Response, err error) (apimodel.PsiphonConfigResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := iox.ReadAllContext(ctx, reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := apimodel.PsiphonConfigResponse{}
|
|
if err := api.jsonCodec().Decode(data, &out); err != nil {
|
|
return nil, err
|
|
}
|
|
if out == nil {
|
|
return nil, ErrJSONLiteralNull
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleTorTargetsAPI) newResponse(ctx context.Context, resp *http.Response, err error) (apimodel.TorTargetsResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := iox.ReadAllContext(ctx, reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := apimodel.TorTargetsResponse{}
|
|
if err := api.jsonCodec().Decode(data, &out); err != nil {
|
|
return nil, err
|
|
}
|
|
if out == nil {
|
|
return nil, ErrJSONLiteralNull
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleURLsAPI) newResponse(ctx context.Context, resp *http.Response, err error) (*apimodel.URLsResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := iox.ReadAllContext(ctx, reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.URLsResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleOpenReportAPI) newResponse(ctx context.Context, resp *http.Response, err error) (*apimodel.OpenReportResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := iox.ReadAllContext(ctx, reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.OpenReportResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleSubmitMeasurementAPI) newResponse(ctx context.Context, resp *http.Response, err error) (*apimodel.SubmitMeasurementResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := iox.ReadAllContext(ctx, reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.SubmitMeasurementResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|