-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
33 lines (26 loc) · 884 Bytes
/
server.go
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
32
33
package main
import (
"log"
"net/http"
cli "gopkg.in/alecthomas/kingpin.v2"
)
var (
port = cli.Flag("port", "port").Short('p').String()
servePath = cli.Flag("servePath", "serve path").Short('s').Default("./static").String()
baseURL = cli.Flag("baseUrl", "base url").Short('b').Default("/").String()
certFile = cli.Flag("cert", "certificate").Short('c').Default("").String()
certKey = cli.Flag("key", "certificate key").Short('k').Default("").String()
)
func main() {
cli.Parse()
if *port == "" {
log.Fatal("you must specify a port")
}
http.Handle(*baseURL, http.StripPrefix(*baseURL, http.FileServer(http.Dir(*servePath))))
log.Printf("Listening on http://0.0.0.0:" + *port)
if *certFile != "" && *certKey != "" {
log.Fatal(http.ListenAndServeTLS(":"+*port, *certFile, *certKey, nil))
} else {
log.Fatal(http.ListenAndServe(":"+*port, nil))
}
}