Skip to content

Commit

Permalink
feat(example_server): Add /slow{1,10,30,60}s endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejsika committed Nov 14, 2022
1 parent 2907d43 commit 618e426
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/example_server/example_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"os"
"strconv"
"time"

"github.com/sikalabs/slu/cmd/root"
"github.com/sikalabs/slu/version"
Expand All @@ -23,6 +24,22 @@ var Cmd = &cobra.Command{
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "[slu "+version.Version+"] Example HTTP Server! %s %s \n", hostname, portStr)
})
http.HandleFunc("/slow1s", func(w http.ResponseWriter, r *http.Request) {
time.Sleep(1 * time.Second)
fmt.Fprintf(w, "[slu "+version.Version+"] Example HTTP Server (after 1s)! %s %s \n", hostname, portStr)
})
http.HandleFunc("/slow10s", func(w http.ResponseWriter, r *http.Request) {
time.Sleep(10 * time.Second)
fmt.Fprintf(w, "[slu "+version.Version+"] Example HTTP Server (after 10s)! %s %s \n", hostname, portStr)
})
http.HandleFunc("/slow30s", func(w http.ResponseWriter, r *http.Request) {
time.Sleep(30 * time.Second)
fmt.Fprintf(w, "[slu "+version.Version+"] Example HTTP Server (after 30s)! %s %s \n", hostname, portStr)
})
http.HandleFunc("/slow60s", func(w http.ResponseWriter, r *http.Request) {
time.Sleep(60 * time.Second)
fmt.Fprintf(w, "[slu "+version.Version+"] Example HTTP Server (after 60s)! %s %s \n", hostname, portStr)
})
fmt.Println("[slu " + version.Version + "] Server started on 0.0.0.0:" + portStr + ", see http://127.0.0.1:" + portStr)
http.ListenAndServe(":"+portStr, nil)
},
Expand Down

0 comments on commit 618e426

Please sign in to comment.