27 lines
474 B
Go
27 lines
474 B
Go
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)
|
|
}
|