Get web_connectivity to work with dynamic URL fetching

This commit is contained in:
Arturo Filastò 2018-03-23 12:41:06 +01:00
commit 00859e87a6
6 changed files with 104 additions and 8 deletions

33
ooni.go
View file

@ -13,6 +13,7 @@ import (
"github.com/openobservatory/gooni/config"
"github.com/openobservatory/gooni/internal/database"
"github.com/openobservatory/gooni/internal/legacy"
"github.com/openobservatory/gooni/utils"
"github.com/pkg/errors"
)
@ -35,15 +36,39 @@ func Onboarding(c *Config) error {
// Context for OONI Probe
type Context struct {
Config *Config
DB *sqlx.DB
Config *Config
DB *sqlx.DB
Location *utils.LocationInfo
Home string
TempDir string
Home string
TempDir string
dbPath string
configPath string
}
// MaybeLocationLookup will lookup the location of the user unless it's already cached
func (c *Context) MaybeLocationLookup() error {
if c.Location == nil {
return c.LocationLookup()
}
return nil
}
// LocationLookup lookup the location of the user via geoip
func (c *Context) LocationLookup() error {
var err error
dbPath := filepath.Join(c.Home, "geoip")
c.Location, err = utils.GeoIPLookup(dbPath)
if err != nil {
return err
}
return nil
}
// Init the OONI manager
func (c *Context) Init() error {
var err error