Use more general ooni/probe-engine API (#67)

No functional change, just importing less stuff and meddling
much less with the internals of ooni/probe-engine.
This commit is contained in:
Simone Basso
2019-10-28 14:05:05 +01:00
committed by GitHub
parent 1b9bc457b9
commit 946289d6fe
14 changed files with 230 additions and 128 deletions
-27
View File
@@ -2,10 +2,7 @@
package enginex
import (
"encoding/json"
"github.com/apex/log"
"github.com/ooni/probe-engine/model"
)
// Logger is the logger used by the engine.
@@ -13,30 +10,6 @@ var Logger = log.WithFields(log.Fields{
"type": "engine",
})
// MakeGenericTestKeys casts the m.TestKeys to a map[string]interface{}.
//
// Ideally, all tests should have a clear Go structure, well defined, that
// will be stored in m.TestKeys as an interface. This is not already the
// case and it's just valid for tests written in Go. Until all tests will
// be written in Go, we'll keep this glue here to make sure we convert from
// the engine format to the cli format.
//
// This function will first attempt to cast directly to map[string]interface{},
// which is possible for MK tests, and then use JSON serialization and
// de-serialization only if that's required.
func MakeGenericTestKeys(m model.Measurement) (map[string]interface{}, error) {
if result, ok := m.TestKeys.(map[string]interface{}); ok {
return result, nil
}
data, err := json.Marshal(m.TestKeys)
if err != nil {
return nil, err
}
var result map[string]interface{}
err = json.Unmarshal(data, &result)
return result, err
}
// LocationProvider is an interface that returns the current location. The
// github.com/ooni/probe-engine/session.Session implements it.
type LocationProvider interface {