-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
40 lines (32 loc) · 877 Bytes
/
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
package main
import (
"flag"
"log"
"github.com/valyala/fasthttp"
)
var (
DefaultTTL int64
addr string
MemOpt bool
MaxSize int
)
func init() {
flag.Int64Var(&DefaultTTL, "ttl", 4294967295, "default time-to-live of cache objects")
flag.StringVar(&addr, "addr", ":8080", "address to listen on")
flag.BoolVar(&MemOpt, "memopt", false, "Memory optimization (might increase CPU usage)")
flag.IntVar(&MaxSize, "maxsize", 4294967295, "maximum upload size (in bytes)")
}
func main() {
flag.Parse()
// this is the in-mem cache variable that will store all the data
var cache Cache
cache.StartCleanUpWorker()
router := cache.BuildRouter()
log.Printf("Listening on %s\n", addr)
server := &fasthttp.Server{
MaxRequestBodySize: MaxSize,
ReduceMemoryUsage: MemOpt,
Handler: router.Handler,
}
log.Fatal(server.ListenAndServe(addr))
}