Created
August 26, 2015 03:44
-
-
Save IndianGuru/482dbd5074dae83b6d3c to your computer and use it in GitHub Desktop.
File dosasite.go
This file contains 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" | |
"log" | |
"net/http" | |
"os" | |
) | |
func main() { | |
fs := http.FileServer(http.Dir("public")) | |
http.Handle("/", fs) | |
fmt.Println("Listening...") | |
err := http.ListenAndServe(GetPort(), nil) | |
if err != nil { | |
log.Fatal("ListenAndServe: ", err) | |
return | |
} | |
} | |
// Get the Port from the environment so we can run on Heroku (more of this later) | |
func GetPort() string { | |
var port = os.Getenv("PORT") | |
// Set a default port if there is nothing in the environment | |
if port == "" { | |
port = "4747" | |
fmt.Println("INFO: No PORT environment variable detected, defaulting to " + port) | |
} | |
return ":" + port | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment