-
Notifications
You must be signed in to change notification settings - Fork 192
/
messenger.go
134 lines (108 loc) · 4.57 KB
/
messenger.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Copyright (c) 2017, https://github.com/nebulaim
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"flag"
"github.com/golang/glog"
account "github.com/nebulaim/telegramd/biz_server/account/rpc"
auth "github.com/nebulaim/telegramd/biz_server/auth/rpc"
bots "github.com/nebulaim/telegramd/biz_server/bots/rpc"
channels "github.com/nebulaim/telegramd/biz_server/channels/rpc"
contacts "github.com/nebulaim/telegramd/biz_server/contacts/rpc"
help "github.com/nebulaim/telegramd/biz_server/help/rpc"
langpack "github.com/nebulaim/telegramd/biz_server/langpack/rpc"
messages "github.com/nebulaim/telegramd/biz_server/messages/rpc"
payments "github.com/nebulaim/telegramd/biz_server/payments/rpc"
phone "github.com/nebulaim/telegramd/biz_server/phone/rpc"
photos "github.com/nebulaim/telegramd/biz_server/photos/rpc"
stickers "github.com/nebulaim/telegramd/biz_server/stickers/rpc"
updates "github.com/nebulaim/telegramd/biz_server/updates/rpc"
upload "github.com/nebulaim/telegramd/biz_server/upload/rpc"
users "github.com/nebulaim/telegramd/biz_server/users/rpc"
"github.com/nebulaim/telegramd/mtproto"
"net"
"github.com/nebulaim/telegramd/base/redis_client"
"github.com/nebulaim/telegramd/base/mysql_client"
"github.com/BurntSushi/toml"
"fmt"
"github.com/nebulaim/telegramd/biz_model/dal/dao"
"github.com/nebulaim/telegramd/biz_server/delivery"
"github.com/nebulaim/telegramd/grpc_util/middleware/recovery2"
"github.com/nebulaim/telegramd/grpc_util"
)
func init() {
flag.Set("alsologtostderr", "true")
flag.Set("log_dir", "false")
}
type RpcServerConfig struct {
Addr string
}
type RpcClientConfig struct {
ServiceName string
Addr string
}
type BizServerConfig struct{
Server *RpcServerConfig
RpcClient *RpcClientConfig
Mysql []mysql_client.MySQLConfig
Redis []redis_client.RedisConfig
}
// 整合各服务,方便开发调试
func main() {
flag.Parse()
bizServerConfig := &BizServerConfig{}
if _, err := toml.DecodeFile("./biz_server.toml", bizServerConfig); err != nil {
fmt.Errorf("%s\n", err)
return
}
glog.Info(bizServerConfig)
// 初始化mysql_client、redis_client
redis_client.InstallRedisClientManager(bizServerConfig.Redis)
mysql_client.InstallMysqlClientManager(bizServerConfig.Mysql)
// 初始化redis_dao、mysql_dao
dao.InstallMysqlDAOManager(mysql_client.GetMysqlClientManager())
dao.InstallRedisDAOManager(redis_client.GetRedisClientManager())
lis, err := net.Listen("tcp", bizServerConfig.Server.Addr)
if err != nil {
glog.Fatalf("failed to listen: %v", err)
}
delivery.InstallDeliveryInstance(bizServerConfig.RpcClient.Addr)
// var opts []grpc.ServerOption
// grpcServer := grpc.NewServer(opts...)
grpcServer := grpc_recovery2.NewRecoveryServer(grpc_util.BizUnaryRecoveryHandler, grpc_util.BizStreamRecoveryHandler)
// AccountServiceImpl
mtproto.RegisterRPCAccountServer(grpcServer, &account.AccountServiceImpl{})
// AuthServiceImpl
mtproto.RegisterRPCAuthServer(grpcServer, &auth.AuthServiceImpl{})
mtproto.RegisterRPCBotsServer(grpcServer, &bots.BotsServiceImpl{})
mtproto.RegisterRPCChannelsServer(grpcServer, &channels.ChannelsServiceImpl{})
// ContactsServiceImpl
mtproto.RegisterRPCContactsServer(grpcServer, &contacts.ContactsServiceImpl{})
mtproto.RegisterRPCHelpServer(grpcServer, &help.HelpServiceImpl{})
mtproto.RegisterRPCLangpackServer(grpcServer, &langpack.LangpackServiceImpl{})
// MessagesServiceImpl
mtproto.RegisterRPCMessagesServer(grpcServer, &messages.MessagesServiceImpl{})
mtproto.RegisterRPCPaymentsServer(grpcServer, &payments.PaymentsServiceImpl{})
mtproto.RegisterRPCPhoneServer(grpcServer, &phone.PhoneServiceImpl{})
mtproto.RegisterRPCPhotosServer(grpcServer, &photos.PhotosServiceImpl{})
mtproto.RegisterRPCStickersServer(grpcServer, &stickers.StickersServiceImpl{})
mtproto.RegisterRPCUpdatesServer(grpcServer, &updates.UpdatesServiceImpl{})
mtproto.RegisterRPCUploadServer(grpcServer, &upload.UploadServiceImpl{})
mtproto.RegisterRPCUsersServer(grpcServer, &users.UsersServiceImpl{})
glog.Infof("NewRPCServer in {%v}.", bizServerConfig)
grpcServer.Serve(lis)
}