4
This commit is contained in:
parent
e8a06e8edd
commit
db7e6ea1b0
1 changed files with 11 additions and 6 deletions
17
helper.go
17
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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue