-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.go
39 lines (32 loc) · 1.33 KB
/
server.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 thriftserver
import (
"fmt"
"os"
"git.apache.org/thrift.git/lib/go/thrift"
"code.aliyun.com/wyunshare/thrift-server/gen-go/server"
"code.aliyun.com/wyunshare/thrift-server/processor"
"code.aliyun.com/wyunshare/thrift-server/business"
)
func StartServer(address string, port string, handler server.MyService) {
processor := server.NewMyServiceProcessor(handler)
serverTransport, err := thrift.NewTServerSocket(address + ":" + port)
transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
if err != nil {
fmt.Println("Error!", err)
os.Exit(1)
}
server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
fmt.Println("thrift server in", address + ":" + port)
server.Serve()
}
func StartSingleServer(address string, port string, serviceName string, businessService business.IBusinessService) {
businessServiceMap := &business.BusinessServiceMap{
ServiceMap: make(map[string]business.IBusinessService),
}
businessServiceMap.RegisterService(serviceName, businessService)
wyunServiceImpl := processor.WyunServiceImpl{
BusinessServiceMap: businessServiceMap,
}
StartServer(address, port, &wyunServiceImpl)
}