mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-07-04 12:03:43 +02:00
cmd/antelope-v1-mock-server/main.go: adding -d flag for random delays.
This commit is contained in:
parent
228d7ae731
commit
9b28e45295
1 changed files with 9 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -13,6 +14,7 @@ import (
|
||||||
var (
|
var (
|
||||||
listen_host = flag.String("h,host", "localhost", "Host to listen on.")
|
listen_host = flag.String("h,host", "localhost", "Host to listen on.")
|
||||||
listen_port = flag.Int("p", 3333, "Port to listen to.")
|
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) {
|
func getInfo(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -40,6 +42,11 @@ func getInfo(w http.ResponseWriter, r *http.Request) {
|
||||||
ForkDBHeadBlockNum: 100,
|
ForkDBHeadBlockNum: 100,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *delay > 0 {
|
||||||
|
sleep_for := rand.Intn(*delay)
|
||||||
|
time.Sleep(time.Second * time.Duration(sleep_for))
|
||||||
|
}
|
||||||
|
|
||||||
payload, err := leapapi.Json().Marshal(&info)
|
payload, err := leapapi.Json().Marshal(&info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
|
@ -54,6 +61,8 @@ func getInfo(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
rand.Seed(time.Now().Unix())
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
http.HandleFunc("/v1/chain/get_info", getInfo)
|
http.HandleFunc("/v1/chain/get_info", getInfo)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue