-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
63 lines (55 loc) · 1.63 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
56
57
58
59
60
61
62
63
package main
import (
"crypto/tls"
"fmt"
"git.apache.org/thrift.git/lib/go/thrift"
"git.xiaojukeji.com/soda-framework/go-log"
"github.com/yingongzi/php-thrift/gen-go/php_go/idl"
"php-thrift-go-server/client"
"php-thrift-go-server/conf"
"php-thrift-go-server/service"
)
const (
ADDR = "localhost:8999"
)
func main() {
//加载配置文件
conf.LoadConfigFile("conf/service.conf")
config := conf.GoServerConf
//log 模块的初始化
log.Init(&config.LogConf)
defer log.Close()
//Redis模块的初始化
client.InitRedis(config.RedisConf)
// thrift 服务启动
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
transportFactory := thrift.NewTTransportFactory()
secure := false
if err := runServer(transportFactory, protocolFactory, ADDR, secure); err != nil {
fmt.Println("error running server:", err)
}
}
func runServer(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
var transport thrift.TServerTransport
var err error
if secure {
cfg := new(tls.Config)
if cert, err := tls.LoadX509KeyPair("server.crt", "server.key"); err == nil {
cfg.Certificates = append(cfg.Certificates, cert)
} else {
return err
}
transport, err = thrift.NewTSSLServerSocket(addr, cfg)
} else {
transport, err = thrift.NewTServerSocket(addr)
}
if err != nil {
return err
}
//fmt.Printf("%T\n", transport)
handler := service.New()
processor := idl.NewPhp_Go_SvrProcessor(handler)
server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)
fmt.Println("Starting the simple server... on ", addr)
return server.Serve()
}