()
| 16 | ) |
| 17 | |
| 18 | func main() { |
| 19 | app := cli.NewApp() |
| 20 | |
| 21 | app.Name = "github.com/IceFireDB/IceFireDB/IceFireDB-SQLite" |
| 22 | |
| 23 | app.Flags = []cli.Flag{ |
| 24 | cli.StringFlag{ |
| 25 | Name: "config, c", |
| 26 | Usage: "config file path", |
| 27 | Value: "config/config.yaml", |
| 28 | Required: false, |
| 29 | }, |
| 30 | cli.StringFlag{ |
| 31 | Name: "log,l", |
| 32 | Usage: "log level: debug,info,warning,error", |
| 33 | Value: "info", |
| 34 | }, |
| 35 | } |
| 36 | |
| 37 | app.Before = func(c *cli.Context) error { |
| 38 | log.SetFlags(log.Llongfile) |
| 39 | // init log |
| 40 | lv, err := logrus.ParseLevel(c.String("log")) |
| 41 | if err != nil { |
| 42 | return err |
| 43 | } |
| 44 | logrus.SetLevel(lv) |
| 45 | // init config |
| 46 | confPath := c.String("config") |
| 47 | config.InitConfig(confPath) |
| 48 | return nil |
| 49 | } |
| 50 | |
| 51 | app.Action = func(c *cli.Context) error { |
| 52 | ctx, cancel := context.WithCancel(context.Background()) |
| 53 | stop := make(chan struct{}) |
| 54 | |
| 55 | go func() { |
| 56 | ms := mysql.NewMysqlProxy() |
| 57 | ms.Run(ctx) |
| 58 | stop <- struct{}{} |
| 59 | }() |
| 60 | |
| 61 | return exitSignal(cancel, stop) |
| 62 | } |
| 63 | err := app.Run(os.Args) |
| 64 | if err != nil { |
| 65 | panic(err) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | func exitSignal(cancel context.CancelFunc, stop chan struct{}) error { |
| 70 | sigs := make(chan os.Signal, 1) |
nothing calls this directly
no test coverage detected