diff options
author | ache <ache@ache.one> | 2019-02-12 12:50:54 +0100 |
---|---|---|
committer | ache <ache@ache.one> | 2019-02-12 12:50:54 +0100 |
commit | e4cc4387a6d408521fe6155b36b004bda212ad3e (patch) | |
tree | b17fe5549e55caecd9ae335182113f0bf14fb7c2 | |
parent | Manage GET (the base) (diff) |
Arg management
-rw-r--r-- | server.go | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -6,6 +6,7 @@ import ( "net/http" "os" "html/template" + "flag" ) var tmpl *template.Template @@ -101,8 +102,22 @@ func handleMethod( w http.ResponseWriter, r *http.Request) { } func main() { + var dir string - tmpl = template.Must(template.ParseFiles("dir.html")) + const ( + defaultDir = "." + usageDir = "the directory to serve" + ) + flag.StringVar(&dir, "directory", defaultDir, usageDir) + flag.StringVar(&dir, "d", defaultDir, usageDir+" (shorthand)") + + flag.Parse() + + if dir == "" { + dir = defaultDir + } + + tmpl = template.Must(template.ParseFiles("dir.html")) fmt.Println("Launch server") http.HandleFunc("/", handleMethod) |