Skip to content

Instantly share code, notes, and snippets.

@wemgl
Last active March 10, 2019 13:59
Show Gist options
  • Save wemgl/b74ee963809caa6416dd661447513278 to your computer and use it in GitHub Desktop.
Save wemgl/b74ee963809caa6416dd661447513278 to your computer and use it in GitHub Desktop.
main.go for the simple-server medium post
func main() {
mux := http.NewServeMux()
mux.Handle("/public/", logging(public()))
mux.Handle("/", logging(index()))
port, ok := os.LookupEnv("PORT")
if !ok {
port = "8080"
}
addr := fmt.Sprintf(":%s", port)
server := http.Server{
Addr: addr,
Handler: mux,
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
IdleTimeout: 15 * time.Second,
}
log.Println("main: running simple server on port", port)
if err := server.ListenAndServe(); err != nil {
log.Fatalf("main: couldn't start simple server: %v\n", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment