master
Bel LaPointe 2019-07-16 07:27:33 -06:00
parent a82e9380df
commit 6704fc8302
2 changed files with 13 additions and 12 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
*.key *.key
simpleserve
*.crt *.crt
*.pem *.pem
*.swp *.swp

24
main.go
View File

@ -9,26 +9,26 @@ listing file.
package main package main
import ( import (
"flag" "local/args"
"log" "log"
"net/http" "net/http"
"os" "strings"
"path"
"path/filepath"
) )
func main() { func main() {
exePath, err := filepath.Abs(filepath.Dir(os.Args[0])) fs := args.NewArgSet()
if err != nil { 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) panic(err)
} }
port := flag.String("p", "8100", "port to serve on") d := fs.Get("d").GetString()
directory := flag.String("d", path.Join(exePath, "public"), "the directory of static file to host") p := strings.TrimPrefix(fs.Get("p").GetString(), ":")
flag.Parse()
http.Handle("/", http.FileServer(http.Dir(*directory))) http.Handle("/", http.FileServer(http.Dir(d)))
log.Printf("Serving %s on HTTP port: %s\n", *directory, *port) log.Printf("Serving %s on HTTP port: %s\n", d, p)
log.Fatal(http.ListenAndServe(":"+*port, nil))
log.Fatal(http.ListenAndServe(":"+p, nil))
} }