ooni-probe-cli/internal/engine/ooapi/dependencies.go
Simone Basso 28ce79eff1
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
2021-03-19 09:30:42 +01:00

55 lines
1.5 KiB
Go

package ooapi
import (
"context"
"io"
"net/http"
)
// JSONCodec is a JSON encoder and decoder.
type JSONCodec interface {
// Encode encodes v as a serialized JSON byte slice.
Encode(v interface{}) ([]byte, error)
// Decode decodes the serialized JSON byte slice into v.
Decode(b []byte, v interface{}) error
}
// RequestMaker makes an HTTP request.
type RequestMaker interface {
// NewRequest creates a new HTTP request.
NewRequest(ctx context.Context, method, URL string, body io.Reader) (*http.Request, error)
}
// templateExecutor parses and executes a text template.
type templateExecutor interface {
// Execute takes in input a template string and some piece of data. It
// returns either a string where template parameters have been replaced,
// on success, or an error, on failure.
Execute(tmpl string, v interface{}) (string, error)
}
// HTTPClient is the interface of a generic HTTP client.
type HTTPClient interface {
// Do should work like http.Client.Do.
Do(req *http.Request) (*http.Response, error)
}
// GobCodec is a Gob encoder and decoder.
type GobCodec interface {
// Encode encodes v as a serialized gob byte slice.
Encode(v interface{}) ([]byte, error)
// Decode decodes the serialized gob byte slice into v.
Decode(b []byte, v interface{}) error
}
// KVStore is a key-value store.
type KVStore interface {
// Get gets a value from the key-value store.
Get(key string) ([]byte, error)
// Set stores a value into the key-value store.
Set(key string, value []byte) error
}