1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-api-healthcheck synced 2026-06-16 04:44:55 +02:00

cmd/antelope-v1-mock-server/main.go: adding -d flag for random delays.

This commit is contained in:
Henrik Hautakoski 2023-02-07 12:32:43 +01:00
parent 228d7ae731
commit 9b28e45295
No known key found for this signature in database
GPG key ID: 217490840C18A5D9

View file

@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"math/rand"
"net/http"
"os"
"time"
@ -13,6 +14,7 @@ import (
var (
listen_host = flag.String("h,host", "localhost", "Host to listen on.")
listen_port = flag.Int("p", 3333, "Port to listen to.")
delay = flag.Int("d", 0, "Delays responses randomly between 0 and int seconds.")
)
func getInfo(w http.ResponseWriter, r *http.Request) {
@ -40,6 +42,11 @@ func getInfo(w http.ResponseWriter, r *http.Request) {
ForkDBHeadBlockNum: 100,
}
if *delay > 0 {
sleep_for := rand.Intn(*delay)
time.Sleep(time.Second * time.Duration(sleep_for))
}
payload, err := leapapi.Json().Marshal(&info)
if err != nil {
fmt.Fprintln(os.Stderr, err)
@ -54,6 +61,8 @@ func getInfo(w http.ResponseWriter, r *http.Request) {
}
func main() {
rand.Seed(time.Now().Unix())
flag.Parse()
http.HandleFunc("/v1/chain/get_info", getInfo)