-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (40 loc) · 1.4 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
package main
import (
"./gen-go/zgobandRPC"
"./handler"
"./models"
"fmt"
"github.com/apache/thrift/lib/go/thrift"
"os"
)
func main() {
models.Open()
defer models.Close()
ret := runServer()
if(ret != nil) {
fmt.Println("runSever fail:", ret.Error())
}
}
func runServer() error{
addr := "localhost:9091"
transportFactory := thrift.NewTBufferedTransportFactory(8192)
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
transport, err := thrift.NewTServerSocket(addr)
if(err != nil) {
fmt.Println("err:" , err.Error())
os.Exit(-1)
}
gameHallHandler := handler.NewGameHallHandler()
loginAndRegHandler := handler.NewLoginAndRegHandler()
gameOperatorHandler := handler.NewGameOperatorHandler()
gameOperatorProcessor := zgobandRPC.NewGameOperatorProcessor(gameOperatorHandler)
gameHallHandlerProcessor := zgobandRPC.NewGameHallProcessor(gameHallHandler)
loginAndRegHandlerProcessor := zgobandRPC.NewLoginAndRegProcessor(loginAndRegHandler)
multiProcessor := thrift.NewTMultiplexedProcessor()
multiProcessor.RegisterProcessor("GameHall", gameHallHandlerProcessor)
multiProcessor.RegisterProcessor("LoginAndReg", loginAndRegHandlerProcessor)
multiProcessor.RegisterProcessor("GameOperator", gameOperatorProcessor)
server := thrift.NewTSimpleServer4(multiProcessor, transport, transportFactory, protocolFactory)
fmt.Println("starting the simple server... on", addr)
return server.Serve()
}