forked from machinebox/webFaceID
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (47 loc) · 1.04 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
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"github.com/machinebox/sdk-go/facebox"
"github.com/machinebox/sdk-go/x/boxutil"
)
func main() {
var (
addr = flag.String("addr", ":9000", "address")
state = flag.String("state", "", "facebox state file")
)
flag.Parse()
facebox := facebox.New("http://localhost:8080")
fmt.Println(`Web Face ID by Machine Box - https://machinebox.io/`)
fmt.Println("Waiting for Facebox to be ready...")
boxutil.WaitForReady(context.Background(), facebox)
fmt.Println("Done!")
fmt.Println("Go to:", *addr+"...")
setupFaceboxState(facebox, *state)
srv := NewServer("./assets", facebox)
if err := http.ListenAndServe(*addr, srv); err != nil {
log.Fatalln(err)
}
}
func setupFaceboxState(facebox *facebox.Client, state string) {
if state == "" {
return
}
fmt.Println("Setup facebox state")
f, err := os.Open(state)
if err != nil {
log.Fatalln(err)
return
}
err = facebox.PostState(f)
if err != nil {
log.Fatalln(err)
return
}
fmt.Println("Done!")
f.Close()
}