Start fleshing out database related functions
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/apex/log"
|
||||
"github.com/apex/log/handlers/cli"
|
||||
ooni "github.com/openobservatory/gooni"
|
||||
"github.com/openobservatory/gooni/internal/database"
|
||||
"github.com/prometheus/common/version"
|
||||
)
|
||||
|
||||
@@ -15,7 +16,7 @@ var Cmd = kingpin.New("ooni", "")
|
||||
var Command = Cmd.Command
|
||||
|
||||
// Init should be called by all subcommand that care to have a ooni.OONI instance
|
||||
var Init func() (*ooni.Config, *ooni.OONI, error)
|
||||
var Init func() (*ooni.Config, *ooni.Context, error)
|
||||
|
||||
func init() {
|
||||
configPath := Cmd.Flag("config", "Set a custom config file path").Short('c').String()
|
||||
@@ -28,19 +29,33 @@ func init() {
|
||||
log.Debugf("ooni version %s", version.Version)
|
||||
}
|
||||
|
||||
Init = func() (*ooni.Config, *ooni.OONI, error) {
|
||||
Init = func() (*ooni.Config, *ooni.Context, error) {
|
||||
var c *ooni.Config
|
||||
var err error
|
||||
|
||||
if *configPath != "" {
|
||||
log.Debugf("Reading config file from %s", *configPath)
|
||||
c, err = ooni.ReadConfig(*configPath)
|
||||
} else {
|
||||
log.Debug("Reading default config file")
|
||||
c, err = ooni.ReadDefaultConfigPaths()
|
||||
}
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
o := ooni.New(c)
|
||||
|
||||
dbPath, err := DefaultDatabasePath()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
log.Debugf("Connecting to database sqlite3://%s", dbPath)
|
||||
db, err := database.Connect(dbPath)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
o := ooni.New(c, db)
|
||||
o.Init()
|
||||
return c, o, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user