feat(ooapi): add toplevel client and simplify API (#248)
* feat(ooapi): add toplevel client and simplify API This diff should simplify using ooapi from other packages by adding more abstraction that wraps the existing code. Part of https://github.com/ooni/probe/issues/1355. * fix(ooapi): use correct comment for cloners See https://github.com/ooni/probe-cli/pull/248#discussion_r590663843 * fix(ooapi): make sure the documentation is current See https://github.com/ooni/probe-cli/pull/248#discussion_r590665773 * fix(ooapi): automate copying APIs See https://github.com/ooni/probe-cli/pull/248#discussion_r590665837 * feat(ooapi): add unit tests for clientcall.go See https://github.com/ooni/probe-cli/pull/248#discussion_r590666297 * fix(ooapi): rewrite integration tests to use toplevel API See https://github.com/ooni/probe-cli/pull/248#discussion_r590665084
This commit is contained in:
parent
c22828d369
commit
28ce79eff1
33 changed files with 2090 additions and 795 deletions
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2021-02-26 15:45:50.431349269 +0100 CET m=+0.000196051
|
||||
// 2021-03-10 13:17:31.904167818 +0100 CET m=+0.000077877
|
||||
|
||||
package ooapi
|
||||
|
||||
|
|
@ -12,8 +12,8 @@ import (
|
|||
"github.com/ooni/probe-cli/v3/internal/engine/ooapi/apimodel"
|
||||
)
|
||||
|
||||
// CheckReportIDAPI implements the CheckReportID API.
|
||||
type CheckReportIDAPI struct {
|
||||
// simpleCheckReportIDAPI implements the CheckReportID API.
|
||||
type simpleCheckReportIDAPI struct {
|
||||
BaseURL string // optional
|
||||
HTTPClient HTTPClient // optional
|
||||
JSONCodec JSONCodec // optional
|
||||
|
|
@ -21,28 +21,28 @@ type CheckReportIDAPI struct {
|
|||
UserAgent string // optional
|
||||
}
|
||||
|
||||
func (api *CheckReportIDAPI) baseURL() string {
|
||||
func (api *simpleCheckReportIDAPI) baseURL() string {
|
||||
if api.BaseURL != "" {
|
||||
return api.BaseURL
|
||||
}
|
||||
return "https://ps1.ooni.io"
|
||||
}
|
||||
|
||||
func (api *CheckReportIDAPI) requestMaker() RequestMaker {
|
||||
func (api *simpleCheckReportIDAPI) requestMaker() RequestMaker {
|
||||
if api.RequestMaker != nil {
|
||||
return api.RequestMaker
|
||||
}
|
||||
return &defaultRequestMaker{}
|
||||
}
|
||||
|
||||
func (api *CheckReportIDAPI) jsonCodec() JSONCodec {
|
||||
func (api *simpleCheckReportIDAPI) jsonCodec() JSONCodec {
|
||||
if api.JSONCodec != nil {
|
||||
return api.JSONCodec
|
||||
}
|
||||
return &defaultJSONCodec{}
|
||||
}
|
||||
|
||||
func (api *CheckReportIDAPI) httpClient() HTTPClient {
|
||||
func (api *simpleCheckReportIDAPI) httpClient() HTTPClient {
|
||||
if api.HTTPClient != nil {
|
||||
return api.HTTPClient
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ func (api *CheckReportIDAPI) httpClient() HTTPClient {
|
|||
}
|
||||
|
||||
// Call calls the CheckReportID API.
|
||||
func (api *CheckReportIDAPI) Call(ctx context.Context, req *apimodel.CheckReportIDRequest) (*apimodel.CheckReportIDResponse, error) {
|
||||
func (api *simpleCheckReportIDAPI) Call(ctx context.Context, req *apimodel.CheckReportIDRequest) (*apimodel.CheckReportIDResponse, error) {
|
||||
httpReq, err := api.newRequest(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -62,8 +62,8 @@ func (api *CheckReportIDAPI) Call(ctx context.Context, req *apimodel.CheckReport
|
|||
return api.newResponse(api.httpClient().Do(httpReq))
|
||||
}
|
||||
|
||||
// CheckInAPI implements the CheckIn API.
|
||||
type CheckInAPI struct {
|
||||
// simpleCheckInAPI implements the CheckIn API.
|
||||
type simpleCheckInAPI struct {
|
||||
BaseURL string // optional
|
||||
HTTPClient HTTPClient // optional
|
||||
JSONCodec JSONCodec // optional
|
||||
|
|
@ -71,28 +71,28 @@ type CheckInAPI struct {
|
|||
UserAgent string // optional
|
||||
}
|
||||
|
||||
func (api *CheckInAPI) baseURL() string {
|
||||
func (api *simpleCheckInAPI) baseURL() string {
|
||||
if api.BaseURL != "" {
|
||||
return api.BaseURL
|
||||
}
|
||||
return "https://ps1.ooni.io"
|
||||
}
|
||||
|
||||
func (api *CheckInAPI) requestMaker() RequestMaker {
|
||||
func (api *simpleCheckInAPI) requestMaker() RequestMaker {
|
||||
if api.RequestMaker != nil {
|
||||
return api.RequestMaker
|
||||
}
|
||||
return &defaultRequestMaker{}
|
||||
}
|
||||
|
||||
func (api *CheckInAPI) jsonCodec() JSONCodec {
|
||||
func (api *simpleCheckInAPI) jsonCodec() JSONCodec {
|
||||
if api.JSONCodec != nil {
|
||||
return api.JSONCodec
|
||||
}
|
||||
return &defaultJSONCodec{}
|
||||
}
|
||||
|
||||
func (api *CheckInAPI) httpClient() HTTPClient {
|
||||
func (api *simpleCheckInAPI) httpClient() HTTPClient {
|
||||
if api.HTTPClient != nil {
|
||||
return api.HTTPClient
|
||||
}
|
||||
|
|
@ -100,7 +100,7 @@ func (api *CheckInAPI) httpClient() HTTPClient {
|
|||
}
|
||||
|
||||
// Call calls the CheckIn API.
|
||||
func (api *CheckInAPI) Call(ctx context.Context, req *apimodel.CheckInRequest) (*apimodel.CheckInResponse, error) {
|
||||
func (api *simpleCheckInAPI) Call(ctx context.Context, req *apimodel.CheckInRequest) (*apimodel.CheckInResponse, error) {
|
||||
httpReq, err := api.newRequest(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -112,8 +112,8 @@ func (api *CheckInAPI) Call(ctx context.Context, req *apimodel.CheckInRequest) (
|
|||
return api.newResponse(api.httpClient().Do(httpReq))
|
||||
}
|
||||
|
||||
// LoginAPI implements the Login API.
|
||||
type LoginAPI struct {
|
||||
// simpleLoginAPI implements the Login API.
|
||||
type simpleLoginAPI struct {
|
||||
BaseURL string // optional
|
||||
HTTPClient HTTPClient // optional
|
||||
JSONCodec JSONCodec // optional
|
||||
|
|
@ -121,28 +121,28 @@ type LoginAPI struct {
|
|||
UserAgent string // optional
|
||||
}
|
||||
|
||||
func (api *LoginAPI) baseURL() string {
|
||||
func (api *simpleLoginAPI) baseURL() string {
|
||||
if api.BaseURL != "" {
|
||||
return api.BaseURL
|
||||
}
|
||||
return "https://ps1.ooni.io"
|
||||
}
|
||||
|
||||
func (api *LoginAPI) requestMaker() RequestMaker {
|
||||
func (api *simpleLoginAPI) requestMaker() RequestMaker {
|
||||
if api.RequestMaker != nil {
|
||||
return api.RequestMaker
|
||||
}
|
||||
return &defaultRequestMaker{}
|
||||
}
|
||||
|
||||
func (api *LoginAPI) jsonCodec() JSONCodec {
|
||||
func (api *simpleLoginAPI) jsonCodec() JSONCodec {
|
||||
if api.JSONCodec != nil {
|
||||
return api.JSONCodec
|
||||
}
|
||||
return &defaultJSONCodec{}
|
||||
}
|
||||
|
||||
func (api *LoginAPI) httpClient() HTTPClient {
|
||||
func (api *simpleLoginAPI) httpClient() HTTPClient {
|
||||
if api.HTTPClient != nil {
|
||||
return api.HTTPClient
|
||||
}
|
||||
|
|
@ -150,7 +150,7 @@ func (api *LoginAPI) httpClient() HTTPClient {
|
|||
}
|
||||
|
||||
// Call calls the Login API.
|
||||
func (api *LoginAPI) Call(ctx context.Context, req *apimodel.LoginRequest) (*apimodel.LoginResponse, error) {
|
||||
func (api *simpleLoginAPI) Call(ctx context.Context, req *apimodel.LoginRequest) (*apimodel.LoginResponse, error) {
|
||||
httpReq, err := api.newRequest(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -162,8 +162,8 @@ func (api *LoginAPI) Call(ctx context.Context, req *apimodel.LoginRequest) (*api
|
|||
return api.newResponse(api.httpClient().Do(httpReq))
|
||||
}
|
||||
|
||||
// MeasurementMetaAPI implements the MeasurementMeta API.
|
||||
type MeasurementMetaAPI struct {
|
||||
// simpleMeasurementMetaAPI implements the MeasurementMeta API.
|
||||
type simpleMeasurementMetaAPI struct {
|
||||
BaseURL string // optional
|
||||
HTTPClient HTTPClient // optional
|
||||
JSONCodec JSONCodec // optional
|
||||
|
|
@ -171,28 +171,28 @@ type MeasurementMetaAPI struct {
|
|||
UserAgent string // optional
|
||||
}
|
||||
|
||||
func (api *MeasurementMetaAPI) baseURL() string {
|
||||
func (api *simpleMeasurementMetaAPI) baseURL() string {
|
||||
if api.BaseURL != "" {
|
||||
return api.BaseURL
|
||||
}
|
||||
return "https://ps1.ooni.io"
|
||||
}
|
||||
|
||||
func (api *MeasurementMetaAPI) requestMaker() RequestMaker {
|
||||
func (api *simpleMeasurementMetaAPI) requestMaker() RequestMaker {
|
||||
if api.RequestMaker != nil {
|
||||
return api.RequestMaker
|
||||
}
|
||||
return &defaultRequestMaker{}
|
||||
}
|
||||
|
||||
func (api *MeasurementMetaAPI) jsonCodec() JSONCodec {
|
||||
func (api *simpleMeasurementMetaAPI) jsonCodec() JSONCodec {
|
||||
if api.JSONCodec != nil {
|
||||
return api.JSONCodec
|
||||
}
|
||||
return &defaultJSONCodec{}
|
||||
}
|
||||
|
||||
func (api *MeasurementMetaAPI) httpClient() HTTPClient {
|
||||
func (api *simpleMeasurementMetaAPI) httpClient() HTTPClient {
|
||||
if api.HTTPClient != nil {
|
||||
return api.HTTPClient
|
||||
}
|
||||
|
|
@ -200,7 +200,7 @@ func (api *MeasurementMetaAPI) httpClient() HTTPClient {
|
|||
}
|
||||
|
||||
// Call calls the MeasurementMeta API.
|
||||
func (api *MeasurementMetaAPI) Call(ctx context.Context, req *apimodel.MeasurementMetaRequest) (*apimodel.MeasurementMetaResponse, error) {
|
||||
func (api *simpleMeasurementMetaAPI) Call(ctx context.Context, req *apimodel.MeasurementMetaRequest) (*apimodel.MeasurementMetaResponse, error) {
|
||||
httpReq, err := api.newRequest(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -212,8 +212,8 @@ func (api *MeasurementMetaAPI) Call(ctx context.Context, req *apimodel.Measureme
|
|||
return api.newResponse(api.httpClient().Do(httpReq))
|
||||
}
|
||||
|
||||
// RegisterAPI implements the Register API.
|
||||
type RegisterAPI struct {
|
||||
// simpleRegisterAPI implements the Register API.
|
||||
type simpleRegisterAPI struct {
|
||||
BaseURL string // optional
|
||||
HTTPClient HTTPClient // optional
|
||||
JSONCodec JSONCodec // optional
|
||||
|
|
@ -221,28 +221,28 @@ type RegisterAPI struct {
|
|||
UserAgent string // optional
|
||||
}
|
||||
|
||||
func (api *RegisterAPI) baseURL() string {
|
||||
func (api *simpleRegisterAPI) baseURL() string {
|
||||
if api.BaseURL != "" {
|
||||
return api.BaseURL
|
||||
}
|
||||
return "https://ps1.ooni.io"
|
||||
}
|
||||
|
||||
func (api *RegisterAPI) requestMaker() RequestMaker {
|
||||
func (api *simpleRegisterAPI) requestMaker() RequestMaker {
|
||||
if api.RequestMaker != nil {
|
||||
return api.RequestMaker
|
||||
}
|
||||
return &defaultRequestMaker{}
|
||||
}
|
||||
|
||||
func (api *RegisterAPI) jsonCodec() JSONCodec {
|
||||
func (api *simpleRegisterAPI) jsonCodec() JSONCodec {
|
||||
if api.JSONCodec != nil {
|
||||
return api.JSONCodec
|
||||
}
|
||||
return &defaultJSONCodec{}
|
||||
}
|
||||
|
||||
func (api *RegisterAPI) httpClient() HTTPClient {
|
||||
func (api *simpleRegisterAPI) httpClient() HTTPClient {
|
||||
if api.HTTPClient != nil {
|
||||
return api.HTTPClient
|
||||
}
|
||||
|
|
@ -250,7 +250,7 @@ func (api *RegisterAPI) httpClient() HTTPClient {
|
|||
}
|
||||
|
||||
// Call calls the Register API.
|
||||
func (api *RegisterAPI) Call(ctx context.Context, req *apimodel.RegisterRequest) (*apimodel.RegisterResponse, error) {
|
||||
func (api *simpleRegisterAPI) Call(ctx context.Context, req *apimodel.RegisterRequest) (*apimodel.RegisterResponse, error) {
|
||||
httpReq, err := api.newRequest(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -262,8 +262,8 @@ func (api *RegisterAPI) Call(ctx context.Context, req *apimodel.RegisterRequest)
|
|||
return api.newResponse(api.httpClient().Do(httpReq))
|
||||
}
|
||||
|
||||
// TestHelpersAPI implements the TestHelpers API.
|
||||
type TestHelpersAPI struct {
|
||||
// simpleTestHelpersAPI implements the TestHelpers API.
|
||||
type simpleTestHelpersAPI struct {
|
||||
BaseURL string // optional
|
||||
HTTPClient HTTPClient // optional
|
||||
JSONCodec JSONCodec // optional
|
||||
|
|
@ -271,28 +271,28 @@ type TestHelpersAPI struct {
|
|||
UserAgent string // optional
|
||||
}
|
||||
|
||||
func (api *TestHelpersAPI) baseURL() string {
|
||||
func (api *simpleTestHelpersAPI) baseURL() string {
|
||||
if api.BaseURL != "" {
|
||||
return api.BaseURL
|
||||
}
|
||||
return "https://ps1.ooni.io"
|
||||
}
|
||||
|
||||
func (api *TestHelpersAPI) requestMaker() RequestMaker {
|
||||
func (api *simpleTestHelpersAPI) requestMaker() RequestMaker {
|
||||
if api.RequestMaker != nil {
|
||||
return api.RequestMaker
|
||||
}
|
||||
return &defaultRequestMaker{}
|
||||
}
|
||||
|
||||
func (api *TestHelpersAPI) jsonCodec() JSONCodec {
|
||||
func (api *simpleTestHelpersAPI) jsonCodec() JSONCodec {
|
||||
if api.JSONCodec != nil {
|
||||
return api.JSONCodec
|
||||
}
|
||||
return &defaultJSONCodec{}
|
||||
}
|
||||
|
||||
func (api *TestHelpersAPI) httpClient() HTTPClient {
|
||||
func (api *simpleTestHelpersAPI) httpClient() HTTPClient {
|
||||
if api.HTTPClient != nil {
|
||||
return api.HTTPClient
|
||||
}
|
||||
|
|
@ -300,7 +300,7 @@ func (api *TestHelpersAPI) httpClient() HTTPClient {
|
|||
}
|
||||
|
||||
// Call calls the TestHelpers API.
|
||||
func (api *TestHelpersAPI) Call(ctx context.Context, req *apimodel.TestHelpersRequest) (apimodel.TestHelpersResponse, error) {
|
||||
func (api *simpleTestHelpersAPI) Call(ctx context.Context, req *apimodel.TestHelpersRequest) (apimodel.TestHelpersResponse, error) {
|
||||
httpReq, err := api.newRequest(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -312,8 +312,8 @@ func (api *TestHelpersAPI) Call(ctx context.Context, req *apimodel.TestHelpersRe
|
|||
return api.newResponse(api.httpClient().Do(httpReq))
|
||||
}
|
||||
|
||||
// PsiphonConfigAPI implements the PsiphonConfig API.
|
||||
type PsiphonConfigAPI struct {
|
||||
// simplePsiphonConfigAPI implements the PsiphonConfig API.
|
||||
type simplePsiphonConfigAPI struct {
|
||||
BaseURL string // optional
|
||||
HTTPClient HTTPClient // optional
|
||||
JSONCodec JSONCodec // optional
|
||||
|
|
@ -324,8 +324,8 @@ type PsiphonConfigAPI struct {
|
|||
|
||||
// WithToken returns a copy of the API where the
|
||||
// value of the Token field is replaced with token.
|
||||
func (api *PsiphonConfigAPI) WithToken(token string) PsiphonConfigCaller {
|
||||
out := &PsiphonConfigAPI{}
|
||||
func (api *simplePsiphonConfigAPI) WithToken(token string) callerForPsiphonConfigAPI {
|
||||
out := &simplePsiphonConfigAPI{}
|
||||
out.BaseURL = api.BaseURL
|
||||
out.HTTPClient = api.HTTPClient
|
||||
out.JSONCodec = api.JSONCodec
|
||||
|
|
@ -335,28 +335,28 @@ func (api *PsiphonConfigAPI) WithToken(token string) PsiphonConfigCaller {
|
|||
return out
|
||||
}
|
||||
|
||||
func (api *PsiphonConfigAPI) baseURL() string {
|
||||
func (api *simplePsiphonConfigAPI) baseURL() string {
|
||||
if api.BaseURL != "" {
|
||||
return api.BaseURL
|
||||
}
|
||||
return "https://ps1.ooni.io"
|
||||
}
|
||||
|
||||
func (api *PsiphonConfigAPI) requestMaker() RequestMaker {
|
||||
func (api *simplePsiphonConfigAPI) requestMaker() RequestMaker {
|
||||
if api.RequestMaker != nil {
|
||||
return api.RequestMaker
|
||||
}
|
||||
return &defaultRequestMaker{}
|
||||
}
|
||||
|
||||
func (api *PsiphonConfigAPI) jsonCodec() JSONCodec {
|
||||
func (api *simplePsiphonConfigAPI) jsonCodec() JSONCodec {
|
||||
if api.JSONCodec != nil {
|
||||
return api.JSONCodec
|
||||
}
|
||||
return &defaultJSONCodec{}
|
||||
}
|
||||
|
||||
func (api *PsiphonConfigAPI) httpClient() HTTPClient {
|
||||
func (api *simplePsiphonConfigAPI) httpClient() HTTPClient {
|
||||
if api.HTTPClient != nil {
|
||||
return api.HTTPClient
|
||||
}
|
||||
|
|
@ -364,7 +364,7 @@ func (api *PsiphonConfigAPI) httpClient() HTTPClient {
|
|||
}
|
||||
|
||||
// Call calls the PsiphonConfig API.
|
||||
func (api *PsiphonConfigAPI) Call(ctx context.Context, req *apimodel.PsiphonConfigRequest) (apimodel.PsiphonConfigResponse, error) {
|
||||
func (api *simplePsiphonConfigAPI) Call(ctx context.Context, req *apimodel.PsiphonConfigRequest) (apimodel.PsiphonConfigResponse, error) {
|
||||
httpReq, err := api.newRequest(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -380,8 +380,8 @@ func (api *PsiphonConfigAPI) Call(ctx context.Context, req *apimodel.PsiphonConf
|
|||
return api.newResponse(api.httpClient().Do(httpReq))
|
||||
}
|
||||
|
||||
// TorTargetsAPI implements the TorTargets API.
|
||||
type TorTargetsAPI struct {
|
||||
// simpleTorTargetsAPI implements the TorTargets API.
|
||||
type simpleTorTargetsAPI struct {
|
||||
BaseURL string // optional
|
||||
HTTPClient HTTPClient // optional
|
||||
JSONCodec JSONCodec // optional
|
||||
|
|
@ -392,8 +392,8 @@ type TorTargetsAPI struct {
|
|||
|
||||
// WithToken returns a copy of the API where the
|
||||
// value of the Token field is replaced with token.
|
||||
func (api *TorTargetsAPI) WithToken(token string) TorTargetsCaller {
|
||||
out := &TorTargetsAPI{}
|
||||
func (api *simpleTorTargetsAPI) WithToken(token string) callerForTorTargetsAPI {
|
||||
out := &simpleTorTargetsAPI{}
|
||||
out.BaseURL = api.BaseURL
|
||||
out.HTTPClient = api.HTTPClient
|
||||
out.JSONCodec = api.JSONCodec
|
||||
|
|
@ -403,28 +403,28 @@ func (api *TorTargetsAPI) WithToken(token string) TorTargetsCaller {
|
|||
return out
|
||||
}
|
||||
|
||||
func (api *TorTargetsAPI) baseURL() string {
|
||||
func (api *simpleTorTargetsAPI) baseURL() string {
|
||||
if api.BaseURL != "" {
|
||||
return api.BaseURL
|
||||
}
|
||||
return "https://ps1.ooni.io"
|
||||
}
|
||||
|
||||
func (api *TorTargetsAPI) requestMaker() RequestMaker {
|
||||
func (api *simpleTorTargetsAPI) requestMaker() RequestMaker {
|
||||
if api.RequestMaker != nil {
|
||||
return api.RequestMaker
|
||||
}
|
||||
return &defaultRequestMaker{}
|
||||
}
|
||||
|
||||
func (api *TorTargetsAPI) jsonCodec() JSONCodec {
|
||||
func (api *simpleTorTargetsAPI) jsonCodec() JSONCodec {
|
||||
if api.JSONCodec != nil {
|
||||
return api.JSONCodec
|
||||
}
|
||||
return &defaultJSONCodec{}
|
||||
}
|
||||
|
||||
func (api *TorTargetsAPI) httpClient() HTTPClient {
|
||||
func (api *simpleTorTargetsAPI) httpClient() HTTPClient {
|
||||
if api.HTTPClient != nil {
|
||||
return api.HTTPClient
|
||||
}
|
||||
|
|
@ -432,7 +432,7 @@ func (api *TorTargetsAPI) httpClient() HTTPClient {
|
|||
}
|
||||
|
||||
// Call calls the TorTargets API.
|
||||
func (api *TorTargetsAPI) Call(ctx context.Context, req *apimodel.TorTargetsRequest) (apimodel.TorTargetsResponse, error) {
|
||||
func (api *simpleTorTargetsAPI) Call(ctx context.Context, req *apimodel.TorTargetsRequest) (apimodel.TorTargetsResponse, error) {
|
||||
httpReq, err := api.newRequest(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -448,8 +448,8 @@ func (api *TorTargetsAPI) Call(ctx context.Context, req *apimodel.TorTargetsRequ
|
|||
return api.newResponse(api.httpClient().Do(httpReq))
|
||||
}
|
||||
|
||||
// URLsAPI implements the URLs API.
|
||||
type URLsAPI struct {
|
||||
// simpleURLsAPI implements the URLs API.
|
||||
type simpleURLsAPI struct {
|
||||
BaseURL string // optional
|
||||
HTTPClient HTTPClient // optional
|
||||
JSONCodec JSONCodec // optional
|
||||
|
|
@ -457,28 +457,28 @@ type URLsAPI struct {
|
|||
UserAgent string // optional
|
||||
}
|
||||
|
||||
func (api *URLsAPI) baseURL() string {
|
||||
func (api *simpleURLsAPI) baseURL() string {
|
||||
if api.BaseURL != "" {
|
||||
return api.BaseURL
|
||||
}
|
||||
return "https://ps1.ooni.io"
|
||||
}
|
||||
|
||||
func (api *URLsAPI) requestMaker() RequestMaker {
|
||||
func (api *simpleURLsAPI) requestMaker() RequestMaker {
|
||||
if api.RequestMaker != nil {
|
||||
return api.RequestMaker
|
||||
}
|
||||
return &defaultRequestMaker{}
|
||||
}
|
||||
|
||||
func (api *URLsAPI) jsonCodec() JSONCodec {
|
||||
func (api *simpleURLsAPI) jsonCodec() JSONCodec {
|
||||
if api.JSONCodec != nil {
|
||||
return api.JSONCodec
|
||||
}
|
||||
return &defaultJSONCodec{}
|
||||
}
|
||||
|
||||
func (api *URLsAPI) httpClient() HTTPClient {
|
||||
func (api *simpleURLsAPI) httpClient() HTTPClient {
|
||||
if api.HTTPClient != nil {
|
||||
return api.HTTPClient
|
||||
}
|
||||
|
|
@ -486,7 +486,7 @@ func (api *URLsAPI) httpClient() HTTPClient {
|
|||
}
|
||||
|
||||
// Call calls the URLs API.
|
||||
func (api *URLsAPI) Call(ctx context.Context, req *apimodel.URLsRequest) (*apimodel.URLsResponse, error) {
|
||||
func (api *simpleURLsAPI) Call(ctx context.Context, req *apimodel.URLsRequest) (*apimodel.URLsResponse, error) {
|
||||
httpReq, err := api.newRequest(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -498,8 +498,8 @@ func (api *URLsAPI) Call(ctx context.Context, req *apimodel.URLsRequest) (*apimo
|
|||
return api.newResponse(api.httpClient().Do(httpReq))
|
||||
}
|
||||
|
||||
// OpenReportAPI implements the OpenReport API.
|
||||
type OpenReportAPI struct {
|
||||
// simpleOpenReportAPI implements the OpenReport API.
|
||||
type simpleOpenReportAPI struct {
|
||||
BaseURL string // optional
|
||||
HTTPClient HTTPClient // optional
|
||||
JSONCodec JSONCodec // optional
|
||||
|
|
@ -507,28 +507,28 @@ type OpenReportAPI struct {
|
|||
UserAgent string // optional
|
||||
}
|
||||
|
||||
func (api *OpenReportAPI) baseURL() string {
|
||||
func (api *simpleOpenReportAPI) baseURL() string {
|
||||
if api.BaseURL != "" {
|
||||
return api.BaseURL
|
||||
}
|
||||
return "https://ps1.ooni.io"
|
||||
}
|
||||
|
||||
func (api *OpenReportAPI) requestMaker() RequestMaker {
|
||||
func (api *simpleOpenReportAPI) requestMaker() RequestMaker {
|
||||
if api.RequestMaker != nil {
|
||||
return api.RequestMaker
|
||||
}
|
||||
return &defaultRequestMaker{}
|
||||
}
|
||||
|
||||
func (api *OpenReportAPI) jsonCodec() JSONCodec {
|
||||
func (api *simpleOpenReportAPI) jsonCodec() JSONCodec {
|
||||
if api.JSONCodec != nil {
|
||||
return api.JSONCodec
|
||||
}
|
||||
return &defaultJSONCodec{}
|
||||
}
|
||||
|
||||
func (api *OpenReportAPI) httpClient() HTTPClient {
|
||||
func (api *simpleOpenReportAPI) httpClient() HTTPClient {
|
||||
if api.HTTPClient != nil {
|
||||
return api.HTTPClient
|
||||
}
|
||||
|
|
@ -536,7 +536,7 @@ func (api *OpenReportAPI) httpClient() HTTPClient {
|
|||
}
|
||||
|
||||
// Call calls the OpenReport API.
|
||||
func (api *OpenReportAPI) Call(ctx context.Context, req *apimodel.OpenReportRequest) (*apimodel.OpenReportResponse, error) {
|
||||
func (api *simpleOpenReportAPI) Call(ctx context.Context, req *apimodel.OpenReportRequest) (*apimodel.OpenReportResponse, error) {
|
||||
httpReq, err := api.newRequest(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -548,45 +548,45 @@ func (api *OpenReportAPI) Call(ctx context.Context, req *apimodel.OpenReportRequ
|
|||
return api.newResponse(api.httpClient().Do(httpReq))
|
||||
}
|
||||
|
||||
// SubmitMeasurementAPI implements the SubmitMeasurement API.
|
||||
type SubmitMeasurementAPI struct {
|
||||
// simpleSubmitMeasurementAPI implements the SubmitMeasurement API.
|
||||
type simpleSubmitMeasurementAPI struct {
|
||||
BaseURL string // optional
|
||||
HTTPClient HTTPClient // optional
|
||||
JSONCodec JSONCodec // optional
|
||||
RequestMaker RequestMaker // optional
|
||||
TemplateExecutor TemplateExecutor // optional
|
||||
TemplateExecutor templateExecutor // optional
|
||||
UserAgent string // optional
|
||||
}
|
||||
|
||||
func (api *SubmitMeasurementAPI) baseURL() string {
|
||||
func (api *simpleSubmitMeasurementAPI) baseURL() string {
|
||||
if api.BaseURL != "" {
|
||||
return api.BaseURL
|
||||
}
|
||||
return "https://ps1.ooni.io"
|
||||
}
|
||||
|
||||
func (api *SubmitMeasurementAPI) requestMaker() RequestMaker {
|
||||
func (api *simpleSubmitMeasurementAPI) requestMaker() RequestMaker {
|
||||
if api.RequestMaker != nil {
|
||||
return api.RequestMaker
|
||||
}
|
||||
return &defaultRequestMaker{}
|
||||
}
|
||||
|
||||
func (api *SubmitMeasurementAPI) jsonCodec() JSONCodec {
|
||||
func (api *simpleSubmitMeasurementAPI) jsonCodec() JSONCodec {
|
||||
if api.JSONCodec != nil {
|
||||
return api.JSONCodec
|
||||
}
|
||||
return &defaultJSONCodec{}
|
||||
}
|
||||
|
||||
func (api *SubmitMeasurementAPI) templateExecutor() TemplateExecutor {
|
||||
func (api *simpleSubmitMeasurementAPI) templateExecutor() templateExecutor {
|
||||
if api.TemplateExecutor != nil {
|
||||
return api.TemplateExecutor
|
||||
}
|
||||
return &defaultTemplateExecutor{}
|
||||
}
|
||||
|
||||
func (api *SubmitMeasurementAPI) httpClient() HTTPClient {
|
||||
func (api *simpleSubmitMeasurementAPI) httpClient() HTTPClient {
|
||||
if api.HTTPClient != nil {
|
||||
return api.HTTPClient
|
||||
}
|
||||
|
|
@ -594,7 +594,7 @@ func (api *SubmitMeasurementAPI) httpClient() HTTPClient {
|
|||
}
|
||||
|
||||
// Call calls the SubmitMeasurement API.
|
||||
func (api *SubmitMeasurementAPI) Call(ctx context.Context, req *apimodel.SubmitMeasurementRequest) (*apimodel.SubmitMeasurementResponse, error) {
|
||||
func (api *simpleSubmitMeasurementAPI) Call(ctx context.Context, req *apimodel.SubmitMeasurementRequest) (*apimodel.SubmitMeasurementResponse, error) {
|
||||
httpReq, err := api.newRequest(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Reference in a new issue