neato
parent
7cca58f524
commit
ffa14550fd
|
|
@ -1,4 +1,6 @@
|
||||||
*.tar
|
*.tar
|
||||||
simpleserve
|
simpleserve
|
||||||
|
*.tar
|
||||||
*.sw*
|
*.sw*
|
||||||
**.sw*
|
**.sw*
|
||||||
|
server
|
||||||
|
|
|
||||||
16
build.sh
16
build.sh
|
|
@ -1,7 +1,5 @@
|
||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
ss=simpleserve
|
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
init
|
init
|
||||||
server
|
server
|
||||||
|
|
@ -15,15 +13,9 @@ function init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function server() {
|
function server() {
|
||||||
pushd "$GOPATH/src/local/$ss"
|
local f="./server"
|
||||||
local f="$(gobuild)"
|
GOOS=linux CGO_ENABLED=0 go build -o "$f" -a -installsuffix cgo >&2
|
||||||
popd
|
echo "$f"
|
||||||
mv "$f" "./$ss"
|
|
||||||
}
|
|
||||||
|
|
||||||
function gobuild() {
|
|
||||||
GOOS=linux CGO_ENABLED=0 go build -o /tmp/${PWD##*/} -a -installsuffix cgo >&2
|
|
||||||
echo "/tmp/${PWD##*/}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function gitname() {
|
function gitname() {
|
||||||
|
|
@ -35,7 +27,7 @@ function gitname() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function pack() {
|
function pack() {
|
||||||
tar -czf "$1.tar" "$ss" "public"
|
tar -czf "$1.tar" "./server" "./public"
|
||||||
echo "$1.tar"
|
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