-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (38 loc) · 1.13 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
package main
import (
"flag"
"log"
"textscout/api"
"textscout/common"
"textscout/internal/populate"
)
func main() {
// support two commands
// 1. populate the database by parsing the json file
// 2. start the REST server
var commandFlag string
var filePath string
var searchBy string
flag.StringVar(&commandFlag, "command", "", "which command to run. possible values are insertData and runServer")
flag.StringVar(&filePath, "filePath", "", "path to the file to read from")
flag.StringVar(&searchBy, "searchBy", "", "searchBy database or the inmemory inverted index. possible values are database and inmemIndex")
flag.Parse()
config := common.GetConfigOrDie()
if commandFlag == "insertData" {
if filePath == "" {
log.Fatal("specify the filepath to read the data from.")
}
u := &populate.InsertData{
FilePath: filePath,
Config: config,
}
u.InsertMovies()
} else if commandFlag == "runServer" {
if searchBy == "inmemIndex" && filePath == "" {
log.Fatal("specify the filepath to read the data from.")
}
api.StartServer(config, searchBy, filePath)
} else {
log.Fatal("specify a valid command to run")
}
}