Before finishing the ongoing refactoring and leaving whatever is left of netx in tree, I would like to restructure it so that we'll have an easy time next time we need to modify it. Currently, every functionality lives into the `netx.go` file and we have a support file called `httptransport.go`. I would like to reorganize by topic, instead. This would allow future me to more easily perform topic-specific changes. While there, improve `netx`'s documentation and duplicate some of this documentation inside `internal/README.md` to provide pointers to previous documentation, historical context, and some help to understand the logic architecture of network extensions (aka `netx`). Part of https://github.com/ooni/probe-cli/pull/396
26 lines
725 B
Go
26 lines
725 B
Go
package netx
|
|
|
|
//
|
|
// Resolver from Config.
|
|
//
|
|
|
|
import (
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
|
)
|
|
|
|
// NewResolver creates a new resolver from the specified config.
|
|
func NewResolver(config Config) model.Resolver {
|
|
if config.BaseResolver == nil {
|
|
config.BaseResolver = netxlite.NewResolverSystem()
|
|
}
|
|
r := netxlite.WrapResolver(
|
|
model.ValidLoggerOrDefault(config.Logger),
|
|
config.BaseResolver,
|
|
)
|
|
r = netxlite.MaybeWrapWithCachingResolver(config.CacheResolutions, r)
|
|
r = netxlite.MaybeWrapWithStaticDNSCache(config.DNSCache, r)
|
|
r = netxlite.MaybeWrapWithBogonResolver(config.BogonIsError, r)
|
|
return config.Saver.WrapResolver(r) // WAI when config.Saver==nil
|
|
}
|