neato
parent
7cca58f524
commit
ffa14550fd
|
|
@ -1,4 +1,6 @@
|
|||
*.tar
|
||||
simpleserve
|
||||
*.tar
|
||||
*.sw*
|
||||
**.sw*
|
||||
server
|
||||
|
|
|
|||
16
build.sh
16
build.sh
|
|
@ -1,7 +1,5 @@
|
|||
#! /bin/bash
|
||||
|
||||
ss=simpleserve
|
||||
|
||||
function main() {
|
||||
init
|
||||
server
|
||||
|
|
@ -15,15 +13,9 @@ function init() {
|
|||
}
|
||||
|
||||
function server() {
|
||||
pushd "$GOPATH/src/local/$ss"
|
||||
local f="$(gobuild)"
|
||||
popd
|
||||
mv "$f" "./$ss"
|
||||
}
|
||||
|
||||
function gobuild() {
|
||||
GOOS=linux CGO_ENABLED=0 go build -o /tmp/${PWD##*/} -a -installsuffix cgo >&2
|
||||
echo "/tmp/${PWD##*/}"
|
||||
local f="./server"
|
||||
GOOS=linux CGO_ENABLED=0 go build -o "$f" -a -installsuffix cgo >&2
|
||||
echo "$f"
|
||||
}
|
||||
|
||||
function gitname() {
|
||||
|
|
@ -35,7 +27,7 @@ function gitname() {
|
|||
}
|
||||
|
||||
function pack() {
|
||||
tar -czf "$1.tar" "$ss" "public"
|
||||
tar -czf "$1.tar" "./server" "./public"
|
||||
echo "$1.tar"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
Serve is a very simple static file server in go
|
||||
Usage:
|
||||
-p="8100": port to serve on
|
||||
-d=".": the directory of static files to host
|
||||
Navigating to http://localhost:8100 will display the index.html or directory
|
||||
listing file.
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"local/args"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fs := args.NewArgSet()
|
||||
fs.Append(args.STRING, "p", "port to serve", "8100")
|
||||
fs.Append(args.STRING, "d", "static path to serve", "./public")
|
||||
if err := fs.Parse(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
d := fs.Get("d").GetString()
|
||||
p := strings.TrimPrefix(fs.Get("p").GetString(), ":")
|
||||
|
||||
http.Handle("/", http.FileServer(http.Dir(d)))
|
||||
|
||||
log.Printf("Serving %s on HTTP port: %s\n", d, p)
|
||||
|
||||
log.Fatal(http.ListenAndServe(":"+p, nil))
|
||||
}
|
||||
Loading…
Reference in New Issue