Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
drj42 committed Oct 23, 2014
1 parent b1c9a25 commit 707ff9a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Static File Server
==================

This is a bare bones simple static file server, written in Go. Its about as
basic as it can get. It logs all requests to STDOUT. I use this as a Python
SimpleHTTPServer replacement.

Install
=======

Recommended to have $GOPATH/bin in your $PATH
$ go get github.com/drj42/gostatic

Example Usage
=======

Serve $HOME on 192.168.0.10:8000
$ gostatic -port=8000 -host=192.168.0.10 -root=$HOME

Serve current dir on 127.0.0.1:8080
$ gostatic

28 changes: 28 additions & 0 deletions gostatic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"log"
"net/http"
"flag"
)

var root, port, host string

func init() {
flag.StringVar(&root, "root", ".", "Specify the directory to serve files from. Default is the current working directory")
flag.StringVar(&port, "port", "8080", "Specify server port. Default is 8080")
flag.StringVar(&host, "host", "127.0.0.1", "Specify host or IP. Default is 127.0.0.1")
flag.Parse()
}


func main() {
http.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {
log.Printf("%v %v", r.Method, r.URL.String())
http.FileServer(http.Dir(root)).ServeHTTP(w,r)
return
})

log.Printf("Initializing static web server on %v:%v in %v\n", host, port, root)
log.Fatal(http.ListenAndServe(host + ":" + port , nil))
}

0 comments on commit 707ff9a

Please sign in to comment.