Last active
March 10, 2019 13:59
-
-
Save wemgl/b74ee963809caa6416dd661447513278 to your computer and use it in GitHub Desktop.
main.go for the simple-server medium post
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
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