Created
January 7, 2020 19:17
-
-
Save yuriatgoogle/61c8e3378b8e930ff93770a787f5f200 to your computer and use it in GitHub Desktop.
This file contains 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
func main() { | |
r := mux.NewRouter() | |
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
rand.Seed(time.Now().UnixNano()) | |
n := rand.Intn(10) // n will be between 0 and 10 | |
fmt.Printf("randon number was %d\n", n) | |
if n < 6 { | |
http.Error(w, "error!", 500) | |
} else { | |
fmt.Fprintf(w, "Hello World!") | |
} | |
}) | |
http.ListenAndServe(":8080", r) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment