@@ -12,6 +12,9 @@ import (
1212type options struct {
1313 ListenAddress string
1414 Folder string
15+ Certificate string
16+ Key string
17+ HTTPS bool
1518 Verbose bool
1619}
1720
@@ -20,6 +23,9 @@ var opts options
2023func main () {
2124 flag .StringVar (& opts .ListenAddress , "listen" , "0.0.0.0:8000" , "Address:Port" )
2225 flag .StringVar (& opts .Folder , "path" , "." , "Folder" )
26+ flag .BoolVar (& opts .HTTPS , "https" , false , "HTTPS" )
27+ flag .StringVar (& opts .Certificate , "cert" , "" , "Certificate" )
28+ flag .StringVar (& opts .Key , "key" , "" , "Key" )
2329 flag .BoolVar (& opts .Verbose , "v" , false , "Verbose" )
2430 flag .Parse ()
2531
@@ -28,7 +34,14 @@ func main() {
2834 }
2935
3036 log .Printf ("Serving %s on http://%s/..." , opts .Folder , opts .ListenAddress )
31- fmt .Println (http .ListenAndServe (opts .ListenAddress , loglayer (http .FileServer (http .Dir (opts .Folder )))))
37+ if opts .HTTPS {
38+ if opts .Certificate == "" || opts .Key == "" {
39+ log .Fatal ("Certificate or Key file not specified" )
40+ }
41+ fmt .Println (http .ListenAndServeTLS (opts .ListenAddress , opts .Certificate , opts .Key , loglayer (http .FileServer (http .Dir (opts .Folder )))))
42+ } else {
43+ fmt .Println (http .ListenAndServe (opts .ListenAddress , loglayer (http .FileServer (http .Dir (opts .Folder )))))
44+ }
3245}
3346
3447func loglayer (handler http.Handler ) http.Handler {
0 commit comments