[wip] configuration
This commit is contained in:
parent
699614defb
commit
ddfd8bdcef
40
config/config.go
Normal file
40
config/config.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
type DatabaseConfig struct {
|
||||
Type string
|
||||
Dsn string
|
||||
}
|
||||
|
||||
type AnonymizationConfig struct {
|
||||
}
|
||||
|
||||
func LoadDatabaseConfig(c *cli.Context) (error, DatabaseConfig) {
|
||||
config := DatabaseConfig{
|
||||
Type: c.String("type"),
|
||||
Dsn: c.String("dsn"),
|
||||
}
|
||||
|
||||
if config.Type == "" {
|
||||
return errors.New("You must specify a database type"), config
|
||||
}
|
||||
|
||||
if config.Dsn == "" {
|
||||
return errors.New("You must specify a database DSN"), config
|
||||
}
|
||||
|
||||
return nil, config
|
||||
}
|
||||
|
||||
func LoadAnonymizationConfig(c *cli.Context) (error, AnonymizationConfig) {
|
||||
config := AnonymizationConfig{
|
||||
Type: c.String("type"),
|
||||
Dsn: c.String("dsn"),
|
||||
}
|
||||
|
||||
return nil, config
|
||||
}
|
8
go.mod
8
go.mod
|
@ -1,3 +1,11 @@
|
|||
module gitnet.fr/deblan/database-anonymizer
|
||||
|
||||
go 1.22.0
|
||||
|
||||
require github.com/urfave/cli/v2 v2.27.1
|
||||
|
||||
require (
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e // indirect
|
||||
)
|
||||
|
|
8
go.sum
Normal file
8
go.sum
Normal file
|
@ -0,0 +1,8 @@
|
|||
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
|
||||
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
|
||||
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e h1:+SOyEddqYF09QP7vr7CgJ1eti3pY9Fn3LHO1M1r/0sI=
|
||||
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
47
main.go
Normal file
47
main.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/urfave/cli/v2"
|
||||
"gitnet.fr/deblan/database-anonymizer/config"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := &cli.App{
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "type",
|
||||
Value: "",
|
||||
Usage: "type of database (eg: mysql)",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "dsn",
|
||||
Value: "",
|
||||
Usage: "DSN (eg: mysql://user:pass@host/dbname)",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "config",
|
||||
Value: "config.yaml",
|
||||
Usage: "Configuration file",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
err, databaseConfig := config.LoadDatabaseConfig(c)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("%+v\n", databaseConfig)
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue