func main() { fmt.Println("Version:", VERSION) mode := "unknown" if len(os.Args) > 1 { mode = os.Args[1] } if mode != "listen" && mode != "replay" { fmt.Println("Usage: \n\tgor listen -h\n\tgor replay -h") return } // Remove mode attr os.Args = append(os.Args[:1], os.Args[2:]...) flag.Parse() switch mode { case "listen": listener.Run() case "replay": replay.Run() } }
func main() { defer func() { if r := recover(); r != nil { if _, ok := r.(error); !ok { fmt.Errorf("pkg: %v", r) } } }() fmt.Println("Version:", VERSION) if len(os.Args) > 1 { mode = os.Args[1] } if mode != "listen" && mode != "replay" { fmt.Println("Usage: \n\tgor listen -h\n\tgor replay -h") return } // Remove mode attr os.Args = append(os.Args[:1], os.Args[2:]...) flag.Parse() if *cpuprofile != "" { f, err := os.Create(*cpuprofile) if err != nil { log.Fatal(err) } pprof.StartCPUProfile(f) time.AfterFunc(60*time.Second, func() { pprof.StopCPUProfile() f.Close() log.Println("Stop profiling after 60 seconds") }) } if *memprofile != "" { f, err := os.Create(*memprofile) if err != nil { log.Fatal(err) } time.AfterFunc(60*time.Second, func() { pprof.WriteHeapProfile(f) f.Close() }) } switch mode { case "listen": listener.Run() case "replay": replay.Run() } }
func (e *Env) startListener(port int, replayPort int) { listener.Settings.Verbose = e.Verbose listener.Settings.Address = "127.0.0.1" listener.Settings.ReplayAddress = "127.0.0.1:" + strconv.Itoa(replayPort) listener.Settings.Port = port if e.ListenerLimit != 0 { listener.Settings.ReplayLimit = e.ListenerLimit } listener.Run() }