Created
July 9, 2019 23:34
-
-
Save ianfoo/e7490be3fb4ebb61a0fd8c2b762b5032 to your computer and use it in GitHub Desktop.
Simple Hello server (need nontrivial functionality to ensure libc usage)
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 ( | |
| "log" | |
| "net/http" | |
| "os" | |
| "time" | |
| ) | |
| func main() { | |
| http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
| start := time.Now() | |
| defer func() { | |
| log.Printf( | |
| "request for %s from %s in %f", | |
| r.URL.Path, | |
| r.RemoteAddr, | |
| time.Since(start)) | |
| }() | |
| http.Error(w, "Hello there! Everything is 200 OK.", http.StatusOK) | |
| }) | |
| addr := os.Getenv("ADDR") | |
| if addr == "" { | |
| addr = ":4040" | |
| } | |
| log.Fatal(http.ListenAndServe(addr, nil)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment