forked from pascalopitz/simpleserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleserver.go
More file actions
31 lines (25 loc) · 722 Bytes
/
simpleserver.go
File metadata and controls
31 lines (25 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main
import "os"
import "log"
import "strconv"
import "net/http"
import "github.com/codegangsta/cli"
func main() {
app := cli.NewApp()
app.Name = "SimpleServer"
app.Usage = "Simple static server to quickly run in any directory"
app.Flags = []cli.Flag{
cli.StringFlag{"directory, d", ".", "directory"},
cli.IntFlag{"port, p", 8080, "port number"},
}
app.Action = func(c *cli.Context) {
if c.IsSet("directory") == false || c.IsSet("port") == false {
cli.ShowAppHelp(c)
} else {
staticHandler := http.FileServer(http.Dir(c.GlobalString("directory")))
http.Handle("/", staticHandler)
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(c.GlobalInt("port")), nil))
}
}
app.Run(os.Args)
}