go(run.go): add a way to load local breach data
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d9c3fc1d68
commit
1e1f54023e
2
error.go
2
error.go
@ -8,4 +8,6 @@ import "errors"
|
||||
var (
|
||||
errDBNotConfigured = errors.New("Database connection string or database type were not set")
|
||||
errUnsupportedDBType = errors.New("DBTYPE can only be one of postgres or sqlite3")
|
||||
errDBConnFailed = errors.New("Failed to open a connection to the database")
|
||||
errImportFailed = errors.New("Import of local breach data failed")
|
||||
)
|
||||
|
23
run.go
23
run.go
@ -25,6 +25,7 @@ import (
|
||||
"git.dotya.ml/mirre-mt/pcmt/config"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent"
|
||||
moddb "git.dotya.ml/mirre-mt/pcmt/modules/db"
|
||||
"git.dotya.ml/mirre-mt/pcmt/modules/localbreach"
|
||||
"git.dotya.ml/mirre-mt/pcmt/slogging"
|
||||
)
|
||||
|
||||
@ -160,10 +161,15 @@ func run() error { //nolint:gocognit
|
||||
db, err := ent.Open(setting.DbType(), setting.DbConnstring())
|
||||
if err != nil {
|
||||
if doingImport {
|
||||
log.Error("import not possible")
|
||||
log.Error("Import was not possible", "error", err)
|
||||
fmt.Fprintf(os.Stdout, "\033[31m✗\033[0m Import was not possible due to an error: %q\n", err)
|
||||
|
||||
return errImportFailed
|
||||
}
|
||||
|
||||
return fmt.Errorf("failed to open a connection to database: %v", err)
|
||||
log.Errorf("Error while connecting to DB: %q", err)
|
||||
|
||||
return errDBConnFailed
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
@ -179,6 +185,19 @@ func run() error { //nolint:gocognit
|
||||
|
||||
setting.SetDbIsSetUp(true)
|
||||
|
||||
// don't load the app, return early.
|
||||
if doingImport {
|
||||
lb, err := localbreach.Load(*importFlag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("Import succeeded: %+v", lb)
|
||||
fmt.Fprint(os.Stdout, "\033[32m🗸\033[0m Import succeeded \n")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
a := &app.App{}
|
||||
|
||||
if err = a.Init(setting, slogger, db); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user