github.com/qiwihui/DBShield@v0.0.0-20171107092910-fb8553bed8ef/main.go (about) 1 package main 2 3 import ( 4 "flag" 5 "log" 6 _ "net/http/pprof" 7 "runtime" 8 9 "github.com/qiwihui/DBShield/dbshield" 10 ) 11 12 func usage(showUsage bool) { 13 print("DBShield " + dbshield.Version + "\n") 14 if showUsage { 15 flag.Usage() 16 } 17 } 18 19 func main() { 20 runtime.GOMAXPROCS(runtime.NumCPU()) // For Go < 1.5 21 22 config := flag.String("c", "/etc/dbshield.yml", "config `file`") 23 listPatterns := flag.Bool("l", false, "get list of captured patterns") 24 removePattern := flag.String("r", "", "remove a captured pattern") 25 listAbnormals := flag.Bool("a", false, "get list of abnormal queries") 26 showConfig := flag.Bool("k", false, "show parsed config and exit") 27 showVersion := flag.Bool("version", false, "show version") 28 showHelp := flag.Bool("h", false, "show help") 29 purge := flag.Bool("purge", false, "remove internal database") 30 //Parsing command line arguments 31 flag.Parse() 32 33 if *showHelp { 34 usage(true) 35 return 36 } 37 38 if *showVersion { 39 usage(false) 40 return 41 } 42 43 if err := dbshield.SetConfigFile(*config); err != nil { 44 log.Println(err) 45 return 46 } 47 48 if *listPatterns { 49 dbshield.Patterns() 50 return 51 } 52 53 if *removePattern != "" { 54 dbshield.RemovePattern(*removePattern) 55 return 56 } 57 58 if *listAbnormals { 59 dbshield.Abnormals() 60 return 61 } 62 63 if *showConfig { 64 dbshield.ShowConfig() 65 return 66 } 67 68 if *purge { 69 dbshield.Purge() 70 return 71 } 72 73 log.Println(dbshield.Start()) 74 }