refactor: interfaces and data types into the model package (#642)
## Checklist - [x] I have read the [contribution guidelines](https://github.com/ooni/probe-cli/blob/master/CONTRIBUTING.md) - [x] reference issue for this pull request: https://github.com/ooni/probe/issues/1885 - [x] related ooni/spec pull request: N/A Location of the issue tracker: https://github.com/ooni/probe ## Description This PR contains a set of changes to move important interfaces and data types into the `./internal/model` package. The criteria for including an interface or data type in here is roughly that the type should be important and used by several packages. We are especially interested to move more interfaces here to increase modularity. An additional side effect is that, by reading this package, one should be able to understand more quickly how different parts of the codebase interact with each other. This is what I want to move in `internal/model`: - [x] most important interfaces from `internal/netxlite` - [x] everything that was previously part of `internal/engine/model` - [x] mocks from `internal/netxlite/mocks` should also be moved in here as a subpackage
This commit is contained in:
parent
69aca619ea
commit
273b70bacc
275 changed files with 1281 additions and 1375 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/version"
|
||||
)
|
||||
|
||||
|
|
@ -17,7 +18,7 @@ const (
|
|||
DefaultProbeCC = "ZZ"
|
||||
|
||||
// DefaultProbeIP is the default probe IP.
|
||||
DefaultProbeIP = "127.0.0.1"
|
||||
DefaultProbeIP = model.DefaultProbeIP
|
||||
|
||||
// DefaultProbeNetworkName is the default probe network name.
|
||||
DefaultProbeNetworkName = ""
|
||||
|
|
@ -40,13 +41,6 @@ var (
|
|||
DefaultResolverASNString = fmt.Sprintf("AS%d", DefaultResolverASN)
|
||||
)
|
||||
|
||||
// Logger is the definition of Logger used by this package.
|
||||
type Logger interface {
|
||||
Debug(msg string)
|
||||
Debugf(format string, v ...interface{})
|
||||
Infof(format string, v ...interface{})
|
||||
}
|
||||
|
||||
// Results contains geolocate results.
|
||||
type Results struct {
|
||||
// ASN is the autonomous system number.
|
||||
|
|
@ -111,26 +105,17 @@ type Config struct {
|
|||
|
||||
// Logger is the logger to use. If not set, then we will
|
||||
// use a logger that discards all messages.
|
||||
Logger Logger
|
||||
Logger model.Logger
|
||||
|
||||
// UserAgent is the user agent to use. If not set, then
|
||||
// we will use a default user agent.
|
||||
UserAgent string
|
||||
}
|
||||
|
||||
// discardLogger just ignores log messages thrown at it.
|
||||
type discardLogger struct{}
|
||||
|
||||
func (*discardLogger) Debug(msg string) {}
|
||||
|
||||
func (*discardLogger) Debugf(format string, v ...interface{}) {}
|
||||
|
||||
func (*discardLogger) Infof(format string, v ...interface{}) {}
|
||||
|
||||
// NewTask creates a new instance of Task from config.
|
||||
func NewTask(config Config) *Task {
|
||||
if config.Logger == nil {
|
||||
config.Logger = &discardLogger{}
|
||||
config.Logger = model.DiscardLogger
|
||||
}
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = fmt.Sprintf("ooniprobe-engine/%s", version.Version)
|
||||
|
|
|
|||
Loading…
Reference in a new issue