@@ -12,6 +12,9 @@ import (
12
12
type options struct {
13
13
ListenAddress string
14
14
Folder string
15
+ Certificate string
16
+ Key string
17
+ HTTPS bool
15
18
Verbose bool
16
19
}
17
20
@@ -20,6 +23,9 @@ var opts options
20
23
func main () {
21
24
flag .StringVar (& opts .ListenAddress , "listen" , "0.0.0.0:8000" , "Address:Port" )
22
25
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" )
23
29
flag .BoolVar (& opts .Verbose , "v" , false , "Verbose" )
24
30
flag .Parse ()
25
31
@@ -28,7 +34,14 @@ func main() {
28
34
}
29
35
30
36
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
+ }
32
45
}
33
46
34
47
func loglayer (handler http.Handler ) http.Handler {
0 commit comments