Fix tests: split core package into core and base
This commit is contained in:
50
core/base/databases.go
Normal file
50
core/base/databases.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"github.com/safing/portbase/database"
|
||||
|
||||
// database module
|
||||
_ "github.com/safing/portbase/database/dbmodule"
|
||||
|
||||
// module dependencies
|
||||
_ "github.com/safing/portbase/database/storage/bbolt"
|
||||
)
|
||||
|
||||
// Default Values (changeable for testing)
|
||||
var (
|
||||
DefaultDatabaseStorageType = "bbolt"
|
||||
)
|
||||
|
||||
func registerDatabases() error {
|
||||
_, err := database.Register(&database.Database{
|
||||
Name: "core",
|
||||
Description: "Holds core data, such as settings and profiles",
|
||||
StorageType: DefaultDatabaseStorageType,
|
||||
PrimaryAPI: "",
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = database.Register(&database.Database{
|
||||
Name: "cache",
|
||||
Description: "Cached data, such as Intelligence and DNS Records",
|
||||
StorageType: DefaultDatabaseStorageType,
|
||||
PrimaryAPI: "",
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// _, err = database.Register(&database.Database{
|
||||
// Name: "history",
|
||||
// Description: "Historic event data",
|
||||
// StorageType: DefaultDatabaseStorageType,
|
||||
// PrimaryAPI: "",
|
||||
// })
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
return nil
|
||||
}
|
||||
61
core/base/global.go
Normal file
61
core/base/global.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
|
||||
"github.com/safing/portbase/modules/subsystems"
|
||||
|
||||
"github.com/safing/portbase/api"
|
||||
"github.com/safing/portbase/dataroot"
|
||||
"github.com/safing/portbase/modules"
|
||||
"github.com/safing/portbase/notifications"
|
||||
)
|
||||
|
||||
// Default Values (changeable for testing)
|
||||
var (
|
||||
DefaultAPIListenAddress = "127.0.0.1:817"
|
||||
|
||||
dataDir string
|
||||
databaseDir string
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&dataDir, "data", "", "set data directory")
|
||||
flag.StringVar(&databaseDir, "db", "", "alias to --data (deprecated)")
|
||||
|
||||
modules.SetGlobalPrepFn(globalPrep)
|
||||
}
|
||||
|
||||
func globalPrep() error {
|
||||
if dataroot.Root() == nil {
|
||||
// initialize data dir
|
||||
|
||||
// backwards compatibility
|
||||
if dataDir == "" {
|
||||
dataDir = databaseDir
|
||||
}
|
||||
|
||||
// check data dir
|
||||
if dataDir == "" {
|
||||
return errors.New("please set the data directory using --data=/path/to/data/dir")
|
||||
}
|
||||
|
||||
// initialize structure
|
||||
err := dataroot.Initialize(dataDir, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// set api listen address
|
||||
api.SetDefaultAPIListenAddress(DefaultAPIListenAddress)
|
||||
|
||||
// set notification persistence
|
||||
notifications.SetPersistenceBasePath("core:notifications")
|
||||
|
||||
// set subsystem status dir
|
||||
subsystems.SetDatabaseKeySpace("core:status/subsystems")
|
||||
|
||||
return nil
|
||||
}
|
||||
25
core/base/module.go
Normal file
25
core/base/module.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"github.com/safing/portbase/modules"
|
||||
|
||||
// module dependencies
|
||||
_ "github.com/safing/portbase/config"
|
||||
_ "github.com/safing/portbase/rng"
|
||||
)
|
||||
|
||||
func init() {
|
||||
modules.Register("base", nil, registerDatabases, nil, "database", "config", "rng")
|
||||
|
||||
// For prettier subsystem graph, printed with --print-subsystem-graph
|
||||
/*
|
||||
subsystems.Register(
|
||||
"base",
|
||||
"Base",
|
||||
"THE GROUND.",
|
||||
baseModule,
|
||||
"",
|
||||
nil,
|
||||
)
|
||||
*/
|
||||
}
|
||||
Reference in New Issue
Block a user