-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (65 loc) · 1.95 KB
/
main.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"flag"
"fmt"
"net/http"
"time"
"github.com/bradfitz/http2"
)
const version_string = "snusnu 0.3"
var (
// The font that will be used
// TODO: Make this configurable
font = "<link href='http://fonts.googleapis.com/css?family=Lato:300' rel='stylesheet' type='text/css'>"
// The CSS style that will be used for directory listings and when rendering markdown pages
// TODO: Make this configurable
style = "body { background-color: #f0f0f0; color: #0b0b0b; font-family: 'Lato', sans-serif; font-weight: 300; margin: 3.5em; font-size: 1.3em; } a { color: #4010010; font-family: courier; } a:hover { color: #801010; } a:active { color: yellow; } h1 { color: #101010; }"
// List of filenames that should be displayed instead of a directory listing
// TODO: Make this configurable
indexFilenames = []string{"index.html", "index.md", "index.txt"}
)
func main() {
flag.Parse()
path := "."
addr := ":443"
cert := "cert.pem"
key := "key.pem"
// TODO: Use traditional args/flag handling.
// Add support for --help and --version.
if len(flag.Args()) >= 1 {
path = flag.Args()[0]
}
if len(flag.Args()) >= 2 {
addr = flag.Args()[1]
}
if len(flag.Args()) >= 3 {
cert = flag.Args()[2]
}
if len(flag.Args()) >= 4 {
key = flag.Args()[3]
}
fmt.Println(version_string)
fmt.Println()
fmt.Println("HTTP/2 web server for static content")
fmt.Println()
fmt.Println("[arg 1] directory\t", path)
fmt.Println("[arg 2] server addr\t", addr)
fmt.Println("[arg 3] cert file\t", cert)
fmt.Println("[arg 4] key file\t", key)
fmt.Println()
mux := http.NewServeMux()
registerHandlers(mux, path)
s := &http.Server{
Addr: addr,
Handler: mux,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
// Enable HTTP/2 support
http2.ConfigureServer(s, nil)
fmt.Println("Listening...")
if err := s.ListenAndServeTLS(cert, key); err != nil {
fmt.Printf("Fail: %s\n", err)
}
}