Skip to content

Instantly share code, notes, and snippets.

@yeerkkiller1
Created December 31, 2014 01:23
Show Gist options
  • Save yeerkkiller1/1f178d7d6e9002b632e5 to your computer and use it in GitHub Desktop.
Save yeerkkiller1/1f178d7d6e9002b632e5 to your computer and use it in GitHub Desktop.
Simple golang server
package main
import (
"flag"
"fmt"
"log"
"time"
"net/http"
"strconv"
"strings"
//So shiny...
_ "net/http/pprof"
)
func handler(w http.ResponseWriter, r *http.Request) {
// Workaround for Quentin's system configuration.
// For some reason, css files are getting served
// without a content-type...
if strings.HasSuffix(r.URL.Path, ".css") {
w.Header().Set("Content-Type", "text/css")
}
log.Info("Served file", r.URL.Path)
http.ServeFile(w, r, "."+r.URL.Path)
}
func main() {
// setupPrompt()
portNumber := flag.Int("port", 8080, "Sets the port the server listens on for both http requests and websocket connections.")
flag.Parse()
http.HandleFunc("/", handler)
fmt.Println("Beginning HTTP listening on port", *portNumber)
err := http.ListenAndServe(":"+strconv.Itoa(*portNumber), nil)
if err != nil {
log.Fatal("ListenAndServe:", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment