2021-03-04 11:51:07 +01:00
|
|
|
package ooapi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2021-06-04 11:39:00 +02:00
|
|
|
// JSONCodec is a JSON encoder and decoder. Generally, we use a
|
|
|
|
// default JSONCodec in Client. This is the interface to implement
|
|
|
|
// if you want to override such a default.
|
2021-03-04 11:51:07 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-06-04 11:39:00 +02:00
|
|
|
// RequestMaker makes an HTTP request. Generally, we use a
|
|
|
|
// default RequestMaker in Client. This is the interface to implement
|
|
|
|
// if you want to override such a default.
|
2021-03-04 11:51:07 +01:00
|
|
|
type RequestMaker interface {
|
|
|
|
// NewRequest creates a new HTTP request.
|
|
|
|
NewRequest(ctx context.Context, method, URL string, body io.Reader) (*http.Request, error)
|
|
|
|
}
|
|
|
|
|
2021-03-19 09:30:42 +01:00
|
|
|
// templateExecutor parses and executes a text template.
|
|
|
|
type templateExecutor interface {
|
2021-03-04 11:51:07 +01:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2021-06-04 11:39:00 +02:00
|
|
|
// HTTPClient is the interface of a generic HTTP client. The
|
|
|
|
// stdlib's http.Client implements this interface. We use
|
|
|
|
// http.DefaultClient as the default HTTPClient used by Client.
|
|
|
|
// Consumers of this package typically provide a custom HTTPClient
|
|
|
|
// with additional functionality (e.g., DoH, circumvention).
|
2021-03-04 11:51:07 +01:00
|
|
|
type HTTPClient interface {
|
|
|
|
// Do should work like http.Client.Do.
|
|
|
|
Do(req *http.Request) (*http.Response, error)
|
|
|
|
}
|
|
|
|
|
2021-06-04 11:39:00 +02:00
|
|
|
// GobCodec is a Gob encoder and decoder. Generally, we use a
|
|
|
|
// default GobCodec in Client. This is the interface to implement
|
|
|
|
// if you want to override such a default.
|
2021-03-04 11:51:07 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-06-04 11:39:00 +02:00
|
|
|
// KVStore is a key-value store. This is the interface the
|
|
|
|
// client expect for the key-value store used to save persistent
|
|
|
|
// state (typically on the file system).
|
2021-03-04 11:51:07 +01:00
|
|
|
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
|
|
|
|
}
|