forked from deblan/database-anonymizer
add app
This commit is contained in:
parent
3e1f057064
commit
1398fd28e6
2 changed files with 32 additions and 15 deletions
17
app/app.go
Normal file
17
app/app.go
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"gitnet.fr/deblan/database-anonymizer/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type App struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) Run(db *sql.DB, schema config.SchemaConfig) error {
|
||||||
|
fmt.Printf("%+v\n", db)
|
||||||
|
fmt.Printf("%+v\n", schema)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
30
main.go
30
main.go
|
|
@ -1,43 +1,43 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
_ "github.com/lib/pq"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
"gitnet.fr/deblan/database-anonymizer/app"
|
||||||
"gitnet.fr/deblan/database-anonymizer/config"
|
"gitnet.fr/deblan/database-anonymizer/config"
|
||||||
"log"
|
"gitnet.fr/deblan/database-anonymizer/logger"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "type",
|
|
||||||
Value: "",
|
|
||||||
Usage: "type of database (eg: mysql)",
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "dsn",
|
Name: "dsn",
|
||||||
Value: "",
|
Value: "",
|
||||||
Usage: "DSN (eg: mysql://user:pass@host/dbname)",
|
Usage: "DSN (eg: mysql://user:pass@host/dbname)",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "config",
|
Name: "schema",
|
||||||
Value: "config.yaml",
|
Value: "schema.yaml",
|
||||||
Usage: "Configuration file",
|
Usage: "Configuration file",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
err, databaseConfig := config.LoadDatabaseConfig(c)
|
databaseConfig, err := config.LoadDatabaseConfig(c.String("dsn"))
|
||||||
|
logger.LogFatalExitIf(err)
|
||||||
|
|
||||||
if err != nil {
|
db, err := sql.Open(databaseConfig.Type, databaseConfig.Dsn)
|
||||||
log.Fatalf(err.Error())
|
logger.LogFatalExitIf(err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("%+v\n", databaseConfig)
|
schema, err := config.LoadSchemaConfigFromFile(c.String("schema"))
|
||||||
|
logger.LogFatalExitIf(err)
|
||||||
|
|
||||||
return nil
|
app := app.App{}
|
||||||
|
return app.Run(db, schema)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue