Last active
August 5, 2022 05:26
-
-
Save percybolmer/259cbf8a37efd39f7eb4fe273a200cc6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"time" | |
) | |
func main() { | |
// Grab time of startup | |
started := time.Now() | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
// Calculate runtime duration | |
duration := time.Now().Sub(started) | |
if duration.Seconds() > 10 { | |
log.Println("Timeout triggered") | |
w.WriteHeader(http.StatusInternalServerError) | |
w.Write([]byte(`hello gopher`)) | |
} else { | |
w.WriteHeader(http.StatusOK) | |
w.Write([]byte(`hello gopher`)) | |
} | |
}) | |
http.HandleFunc("/aligator", func(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "Hi Mr Aligator") | |
}) | |
log.Fatal(http.ListenAndServe(":8080", nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment