Skip to content

Instantly share code, notes, and snippets.

@wayneashleyberry
Created September 8, 2016 07:51
Show Gist options
  • Save wayneashleyberry/53db664a85187ee8720e570461f149f3 to your computer and use it in GitHub Desktop.
Save wayneashleyberry/53db664a85187ee8720e570461f149f3 to your computer and use it in GitHub Desktop.
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