Skip to content

Instantly share code, notes, and snippets.

@jrsconfitto
Created September 24, 2013 17:12
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 jrsconfitto/6687990 to your computer and use it in GitHub Desktop.
Save jrsconfitto/6687990 to your computer and use it in GitHub Desktop.
Simple static file server in Go
package main
import (
"flag"
"fmt"
"net/http"
"os"
"strings"
"strconv"
)
var port *int
func init() {
port = flag.Int("port", 4000, "The port from which static files will be served.")
flag.Parse()
}
func main() {
currentDirectory, err := os.Getwd()
if err == nil {
thePort := strings.TrimSpace(strconv.Itoa(*port))
fmt.Printf("Serving from http://localhost:%v", thePort)
http.ListenAndServe(":"+thePort, http.FileServer(http.Dir(currentDirectory)))
} else {
fmt.Println(err.Error())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment