Skip to content

Commit

Permalink
with dir
Browse files Browse the repository at this point in the history
  • Loading branch information
txthinking committed Jul 21, 2020
1 parent ee1af97 commit 9a3d5c0
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package main

import (
"flag"
"fmt"
"log"
"net/http"
"os"
"strings"
)

var address string
var dir string

func init() {
flag.StringVar(&address, "l", ":8080", "listen address")
flag.StringVar(&dir, "d", ".", "web root dir")
}

func main() {
s := ":8080"
if len(os.Args) == 2 {
if strings.Contains(os.Args[1], "h") {
fmt.Println("$ httpserver [:8080]")
return
}
s = os.Args[1]
}
fmt.Println("listen http on", s)
log.Println(http.ListenAndServe(s, http.FileServer(http.Dir("."))))
flag.Parse()
fmt.Println("listen http on", address)
log.Println(http.ListenAndServe(address, http.FileServer(http.Dir(dir))))
}

0 comments on commit 9a3d5c0

Please sign in to comment.