-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (32 loc) · 802 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
39
package main
import (
"flag"
"log"
"net/http"
"time"
"github.com/motomux/smart-cooking-server/handler"
tarantool "github.com/tarantool/go-tarantool"
)
func main() {
port := flag.String("port", "80", "port of server")
db := flag.String("db", "smart-cooking-db:3301", "host of db server")
flag.Parse()
opts := tarantool.Opts{
Timeout: 500 * time.Millisecond,
Reconnect: 1 * time.Second,
MaxReconnects: 3,
}
client, err := tarantool.Connect(*db, opts)
if err != nil {
log.Fatalf("Failed to connect: %s, %s", err.Error(), *db)
}
log.Println("Connected to tarantool")
env := &handler.Env{
Client: client,
}
// Handler
mux := handler.NewHandler(env)
// Run server
log.Println("Starting web server on", port)
log.Fatalln(http.ListenAndServe(":"+*port, mux))
}