Skip to content

Commit 7b8ba8d

Browse files
committed
- init
1 parent 14932e4 commit 7b8ba8d

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

Gopkg.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[prune]
2+
go-tests = true
3+
unused-packages = true

main.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"net/http"
6+
"flag"
7+
"fmt"
8+
"os"
9+
)
10+
11+
var (
12+
port string
13+
root string
14+
)
15+
16+
func main() {
17+
flag.StringVar(&port, "port", "", "Port, default is 9999")
18+
flag.StringVar(&root, "root", "", "Absolute path for root directory")
19+
flag.Parse()
20+
21+
if len(root) < 1 {
22+
dir, err := os.Getwd()
23+
if err != nil {
24+
log.Fatal(err)
25+
}
26+
root = dir
27+
}
28+
29+
if len(port) < 1 {
30+
port = "80"
31+
}
32+
33+
http.Handle("/", http.FileServer(http.Dir(root)))
34+
log.Println(fmt.Sprintf("Listening on %s, serving %s", port, root))
35+
http.ListenAndServe(fmt.Sprintf(":%s", port), nil)
36+
}

0 commit comments

Comments
 (0)