-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
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
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 | ||
|
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
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)) | ||
} |