diff --git a/helper.go b/helper.go index 4fb9413..397a95a 100644 --- a/helper.go +++ b/helper.go @@ -462,7 +462,7 @@ func AppRunner(shoudClear bool, runApp func()) { fmt.Println("Recovered:", v) }() - runApp() + go runApp() <-ctx.Done() //do stuff after ending @@ -470,21 +470,26 @@ func AppRunner(shoudClear bool, runApp func()) { log.Println("AppRunner stopped") os.Exit(0) } - +func handlerOutput(w http.ResponseWriter, r *http.Request, str ...string) { + fmt.Fprintln(w, str[0]+": "+r.URL.Path+" "+str[1]) +} func StartTestHTTPServer(port int, name string) { p := strconv.Itoa(port) go func() { - fmt.Println("Test server (" + name + "): listening port " + p) + + // fmt.Println("Test server (" + name + "): listening port " + p) + fmt.Println("Starting Test server (" + name + ") at " + p) // fmt.Println("Test server is running at http://" + GetIP() + ":" + p) r := mux.NewRouter() r.Path("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, r.Host+"/ OK") + handlerOutput(w, r, name, "/") }) r.Path("/test1").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, r.Host+"/test1 OK") + handlerOutput(w, r, name, "/test1") }) r.Path("/test2").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, r.Host+"/test2 OK") + handlerOutput(w, r, name, "/test2") + }) err := http.ListenAndServe(":"+p, r) if err != nil {