/
main.go
38 lines (30 loc) · 921 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
package main
import (
"flag"
"fmt"
"os"
"github.com/cwi-dis/mozillahubs-datalogger/server"
"github.com/cwi-dis/mozillahubs-datalogger/util"
)
// main parses the command line arguments which contain the output path as
// positional argument and optionally a port for the HTTP server specified by
// the flag -p
func main() {
port := flag.Int("p", 6000, "Port to listen on")
flag.Parse()
if len(flag.Args()) == 0 {
fmt.Println("USAGE:", os.Args[0], "[-p port] saveDir")
os.Exit(1)
}
// Get target directory from command line args
saveDir := flag.Arg(0)
// Check if target directory exists and create it if not
if err := util.CheckAndCreateFolder(saveDir); err != nil {
fmt.Println("Could not create output directory", saveDir)
os.Exit(1)
}
// Ignore SIGHUP so the process isn't killed when the terminal session ends
util.IgnoreSighup()
// Start server
server.StartServer(saveDir, *port)
}