Created
September 8, 2016 07:51
-
-
Save wayneashleyberry/53db664a85187ee8720e570461f149f3 to your computer and use it in GitHub Desktop.
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 ( | |
"fmt" | |
"net/http" | |
"os" | |
"github.com/gorilla/handlers" | |
"github.com/gorilla/mux" | |
) | |
func main() { | |
r := mux.NewRouter() | |
r.NotFoundHandler = http.HandlerFunc(NotFoundHandler) | |
r.HandleFunc("/", HomeHandler) | |
gzip := handlers.CompressHandler(r) | |
http.ListenAndServe(":"+os.Getenv("PORT"), gzip) | |
} | |
func NotFoundHandler(w http.ResponseWriter, r *http.Request) { | |
w.WriteHeader(http.StatusNotFound) | |
fmt.Fprintf(w, "404 - not found") | |
} | |
func HomeHandler(w http.ResponseWriter, r *http.Request) { | |
w.WriteHeader(http.StatusOK) | |
fmt.Fprintf(w, "Hello, World!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment