-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
58 lines (49 loc) · 1.12 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
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"github.com/machinebox/sdk-go/boxutil"
"github.com/machinebox/sdk-go/tagbox"
)
func main() {
var (
addr = flag.String("addr", ":9000", "address")
state = flag.String("state", "./reddit.machinebox.tagbox", "tagbox state file")
csv = flag.String("csv", "./reddit.csv", "cvs file")
)
flag.Parse()
tagbox := tagbox.New("http://localhost:8080")
fmt.Println(`visualsearch by Machine Box - https://machinebox.io/`)
fmt.Println("Loading data from csv")
items, err := LoadData(*csv)
if err != nil {
log.Fatalln(err)
return
}
fmt.Println("Done!")
fmt.Println("Waiting for Tagbox to be ready...")
boxutil.WaitForReady(context.Background(), tagbox)
fmt.Println("Done!")
fmt.Println("Setup tagbox state")
f, err := os.Open(*state)
if err != nil {
log.Fatalln(err)
return
}
err = tagbox.PostState(f)
if err != nil {
log.Fatalln(err)
return
}
fmt.Println("Done!")
f.Close()
fmt.Println("Go to:", *addr+"...")
srv := NewServer("./assets", tagbox, items)
if err := http.ListenAndServe(*addr, srv); err != nil {
log.Fatalln(err)
}
}