diff --git a/.gitignore b/.gitignore index b402e50..94632fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.key +simpleserve *.crt *.pem *.swp diff --git a/main.go b/main.go index 1dffd78..5323f01 100644 --- a/main.go +++ b/main.go @@ -9,26 +9,26 @@ listing file. package main import ( - "flag" + "local/args" "log" "net/http" - "os" - "path" - "path/filepath" + "strings" ) func main() { - exePath, err := filepath.Abs(filepath.Dir(os.Args[0])) - if err != nil { + 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) } - port := flag.String("p", "8100", "port to serve on") - directory := flag.String("d", path.Join(exePath, "public"), "the directory of static file to host") - flag.Parse() + d := fs.Get("d").GetString() + p := strings.TrimPrefix(fs.Get("p").GetString(), ":") - 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.Fatal(http.ListenAndServe(":"+*port, nil)) + log.Printf("Serving %s on HTTP port: %s\n", d, p) + + log.Fatal(http.ListenAndServe(":"+p, nil)) }