From 615ed7b666251b8a2faef4c97ada1b62ce8b05be Mon Sep 17 00:00:00 2001 From: Beppe Vanrolleghem Date: Wed, 25 Mar 2020 14:30:14 +0100 Subject: [PATCH] added forced errors for fault injection --- src/main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main.go b/src/main.go index e10e4c6..d602bf1 100644 --- a/src/main.go +++ b/src/main.go @@ -3,13 +3,25 @@ package main import ( "fmt" "net/http" + "time" ) func main() { http.HandleFunc("/", HelloServer) + http.HandleFunc("/err/500", errorInternal) + http.HandleFunc("/err/timeout", errorTimeout) http.ListenAndServe(":80", nil) } func HelloServer(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "{\"serverName\":\"backend-server\",\"success:false\",\"version\": \"experimental\"}") +} + +func errorInternal(w http.ResponseWriter, r *http.Request) { + panic(500) +} + +func errorTimeout(w http.ResponseWriter, r *http.Request) { + time.Sleep(2 * time.Second) + fmt.Fprintf(w, "this was delayed by 2 seconds") } \ No newline at end of file