Skip to content

Instantly share code, notes, and snippets.

@IndianGuru
Created August 26, 2015 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndianGuru/482dbd5074dae83b6d3c to your computer and use it in GitHub Desktop.
Save IndianGuru/482dbd5074dae83b6d3c to your computer and use it in GitHub Desktop.
File dosasite.go
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