Skip to content

Instantly share code, notes, and snippets.

@ianfoo
Created July 9, 2019 23:34
Show Gist options
  • Select an option

  • Save ianfoo/e7490be3fb4ebb61a0fd8c2b762b5032 to your computer and use it in GitHub Desktop.

Select an option

Save ianfoo/e7490be3fb4ebb61a0fd8c2b762b5032 to your computer and use it in GitHub Desktop.
Simple Hello server (need nontrivial functionality to ensure libc usage)
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