-
Notifications
You must be signed in to change notification settings - Fork 118
/
titan.go
67 lines (58 loc) · 1.14 KB
/
titan.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
59
60
61
62
63
64
65
66
67
package integration
import (
"fmt"
"log"
"net"
"go.uber.org/zap"
"github.com/distributedio/titan"
"github.com/distributedio/titan/conf"
"github.com/distributedio/titan/context"
"github.com/distributedio/titan/db"
)
var (
svr *titan.Server
cfg = &conf.Server{
Listen: ServerAddr,
MaxConnection: 10000,
Auth: "",
}
tikvConf = conf.MockConf().TiKV
//ServerAddr default server addr
ServerAddr = "127.0.0.1:17369"
lis net.Listener
)
//SetAuth default no verify
// specify auth to enable validation
func SetAuth(auth string) {
cfg.Auth = auth
}
// SetAddr set server listen addr
func SetAddr(addr string) {
cfg.Listen = addr
}
//Start start server
//1.open db
//2.start server fd
func Start() {
zap.ReplaceGlobals(zap.NewNop())
var err error
store, err := db.Open(&tikvConf)
if err != nil {
log.Fatalln(err)
}
svr = titan.New(&context.ServerContext{
RequirePass: cfg.Auth,
Store: store,
ListZipThreshold: 100,
})
err = svr.ListenAndServe(cfg.Listen)
if err != nil {
return
}
}
//Close close server listen fd
func Close() {
if err := svr.Stop(); err != nil {
fmt.Println(err)
}
}