Initial commit
This commit is contained in:
26
cmd/fakeserver/main.go
Normal file
26
cmd/fakeserver/main.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func fakeHandler(w http.ResponseWriter, req *http.Request) {
|
||||
n := 200 + rand.Intn(600) // 200 - 800
|
||||
time.Sleep(time.Duration(n) * time.Millisecond)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, `{"time": %d}`, n)
|
||||
log.Printf("Response time: %dms", n)
|
||||
}
|
||||
|
||||
func main() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
http.HandleFunc("/", fakeHandler)
|
||||
|
||||
http.ListenAndServe(":8090", nil)
|
||||
}
|
||||
Reference in New Issue
Block a user