-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (41 loc) · 1.35 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
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"git.sr.ht/~seanld/houston"
"golang.org/x/time/rate"
)
func main() {
r := houston.BlankRouter()
dir, err := os.Getwd()
if err != nil {
fmt.Println("ERROR: Failed to get working directory.")
}
srvPath := flag.String("path", "static", "Path to directory, from which static content is served")
addrFlag := flag.String("addr", "0.0.0.0", "IP address to listen on")
portFlag := flag.Int("port", 1965, "Port to listen on")
crtPathFlag := flag.String("cert", "", "Path to TLS certificate file")
keyPathFlag := flag.String("key", "", "Path to TLS private key file")
noRateLimitingFlag := flag.Bool("nolimit", false, "Disable rate-limiting")
noLoggingFlag := flag.Bool("nolog", false, "Disable connection logging")
bucketSizeFlag := flag.Int("bs", 2, "Rate-limiting bucket size")
maxRateFlag := flag.Int("trickle", 2, "Rate-limiting trickle rate")
flag.Parse()
staticPath := filepath.Join(dir, *srvPath)
r.Sandbox("/", staticPath)
srv := houston.NewServer(&r, &houston.ServerConfig{
Hostname: *addrFlag,
Port: uint16(*portFlag),
CertificatePath: *crtPathFlag,
KeyPath: *keyPathFlag,
EnableLimiting: !*noRateLimitingFlag,
BucketSize: *bucketSizeFlag,
MaxRate: rate.Limit(*maxRateFlag),
EnableLog: !*noLoggingFlag,
LogFilePath: "june.log",
})
fmt.Println("Running...")
srv.Start()
}