-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
70 lines (59 loc) · 1.6 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
package main
import (
"flag"
"io"
"os"
"github.com/aws/aws-lambda-go/lambdaurl"
"golang.org/x/sync/errgroup"
)
func main() {
cfg := loadConfig()
if os.Getenv("AWS_LAMBDA_RUNTIME_API") != "" {
d := newDifferServer(cfg)
lambdaurl.Start(d.getHander())
return
}
sim := flag.String("sim", "", "file with paths to load")
simBase := flag.String("base", "", "file with base paths")
analyze := flag.Bool("analyze", false, "analyze logs")
narExpand := flag.Bool("narexpand", false, "run ExpandNar")
narCollapse := flag.Bool("narcollapse", false, "run CollapseNar")
dlSpeed := flag.Float64("dlspeed", 40, "assumed download speed in Mbps")
flag.Parse()
switch {
case *sim != "" || *simBase != "":
panicIfTrue(*sim == "" || *simBase == "", "must specify -base and -sim")
panicIfErr(simulate(cfg, *simBase, *sim))
return
case *analyze:
opts := analyzeOptions{dlSpeed: *dlSpeed}
for _, arg := range flag.Args() {
analyzeLog(arg, opts)
}
return
case *narExpand:
panicIfErr2(io.Copy(os.Stdout, ExpandNar(os.Stdin, cfgToNarExpanderOptions(cfg))))
return
case *narCollapse:
panicIfErr2(io.Copy(os.Stdout, CollapseNar(os.Stdin, cfgToNarExpanderOptions(cfg))))
return
}
var g errgroup.Group
if cfg.RunSubstituter {
catalog := newCatalog(cfg)
catalog.start()
subst := newLocalSubstituter(cfg, catalog)
g.Go(subst.serve)
}
if cfg.RunDiffer {
differ := newDifferServer(cfg)
g.Go(differ.serve)
}
g.Wait()
}
func cfgToNarExpanderOptions(cfg *config) narExpanderOptions {
return narExpanderOptions{
BufferEntries: cfg.NarExpBufferEnt,
BufferBytes: cfg.NarExpBufferBytes,
}
}