Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
im-microservice
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Li Feifei
im-microservice
Commits
03d51449
Commit
03d51449
authored
Jul 07, 2020
by
Li Feifei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add grpc deadlines
parent
b5af48d0
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
10 deletions
+63
-10
helper.go
helper/helper.go
+11
-0
Registration_services.go
initialization/Registration_services.go
+1
-1
main.go
sevice/im_configure/main.go
+16
-4
main.go
sevice/im_friend_request/main.go
+15
-0
im_user_db.go
sevice/im_user/im_user_db.go
+0
-1
main.go
sevice/im_user_relationship/main.go
+20
-4
No files found.
helper/helper.go
View file @
03d51449
...
@@ -46,3 +46,13 @@ func Paginate(count, step, page int64) (int64, int64) {
...
@@ -46,3 +46,13 @@ func Paginate(count, step, page int64) (int64, int64) {
total
:=
int64
(
math
.
Ceil
(
float64
(
count
)
/
float64
(
step
)))
total
:=
int64
(
math
.
Ceil
(
float64
(
count
)
/
float64
(
step
)))
return
offset
,
total
return
offset
,
total
}
}
func
TimeOutCanceled
(
ctx
context
.
Context
)
(
err
error
)
{
select
{
case
<-
ctx
.
Done
()
:
err
=
status
.
Error
(
codes
.
Canceled
,
"Client cancelled, abandoning."
)
break
}
return
}
\ No newline at end of file
initialization/Registration_services.go
View file @
03d51449
...
@@ -46,7 +46,7 @@ func init() {
...
@@ -46,7 +46,7 @@ func init() {
grpc
.
UnaryInterceptor
(
grpc_middleware
.
ChainUnaryServer
(
grpc
.
UnaryInterceptor
(
grpc_middleware
.
ChainUnaryServer
(
middleware
.
Interceptor
,
middleware
.
Interceptor
,
grpc_validator
.
UnaryServerInterceptor
(),
grpc_validator
.
UnaryServerInterceptor
(),
middleware
.
Auth
,
//
middleware.Auth,
grpc_recovery
.
UnaryServerInterceptor
(
middleware
.
RecoveryInterceptor
()),
grpc_recovery
.
UnaryServerInterceptor
(
middleware
.
RecoveryInterceptor
()),
grpc_zap
.
UnaryServerInterceptor
(
middleware
.
ZapInterceptor
()),
grpc_zap
.
UnaryServerInterceptor
(
middleware
.
ZapInterceptor
()),
)))
)))
...
...
sevice/im_configure/main.go
View file @
03d51449
...
@@ -17,7 +17,10 @@ type ConfigureSevice struct {
...
@@ -17,7 +17,10 @@ type ConfigureSevice struct {
func
(
cs
*
ConfigureSevice
)
Add
(
ctx
context
.
Context
,
func
(
cs
*
ConfigureSevice
)
Add
(
ctx
context
.
Context
,
in
*
pb
.
ConfigureRequest
)
(
reply
*
pb
.
ConfigureReply
,
err
error
)
{
in
*
pb
.
ConfigureRequest
)
(
reply
*
pb
.
ConfigureReply
,
err
error
)
{
// 请求超时
if
err
=
helper
.
TimeOutCanceled
(
ctx
);
err
!=
nil
{
return
}
configure_add_struct
:=
vs
.
NewConfigureAddStruct
(
in
)
configure_add_struct
:=
vs
.
NewConfigureAddStruct
(
in
)
if
err
=
helper
.
Valiator
(
configure_add_struct
);
err
!=
nil
{
if
err
=
helper
.
Valiator
(
configure_add_struct
);
err
!=
nil
{
return
return
...
@@ -41,7 +44,10 @@ func (cs *ConfigureSevice) Add(ctx context.Context,
...
@@ -41,7 +44,10 @@ func (cs *ConfigureSevice) Add(ctx context.Context,
func
(
cs
*
ConfigureSevice
)
Delete
(
ctx
context
.
Context
,
func
(
cs
*
ConfigureSevice
)
Delete
(
ctx
context
.
Context
,
in
*
pb
.
ConfigureDelRequest
)
(
reply
*
pb
.
ConfigureReply
,
err
error
)
{
in
*
pb
.
ConfigureDelRequest
)
(
reply
*
pb
.
ConfigureReply
,
err
error
)
{
// 请求超时
if
err
=
helper
.
TimeOutCanceled
(
ctx
);
err
!=
nil
{
return
}
// 执行删除操作
// 执行删除操作
if
err
=
DelConfigure
(
in
.
CompanyUserId
);
err
!=
nil
{
if
err
=
DelConfigure
(
in
.
CompanyUserId
);
err
!=
nil
{
return
return
...
@@ -52,7 +58,10 @@ func (cs *ConfigureSevice) Delete(ctx context.Context,
...
@@ -52,7 +58,10 @@ func (cs *ConfigureSevice) Delete(ctx context.Context,
func
(
cs
*
ConfigureSevice
)
Select
(
ctx
context
.
Context
,
func
(
cs
*
ConfigureSevice
)
Select
(
ctx
context
.
Context
,
in
*
pb
.
GetAllRequest
)
(
reply
*
pb
.
GetAllReply
,
err
error
)
{
in
*
pb
.
GetAllRequest
)
(
reply
*
pb
.
GetAllReply
,
err
error
)
{
// 请求超时
if
err
=
helper
.
TimeOutCanceled
(
ctx
);
err
!=
nil
{
return
}
reply
=
&
pb
.
GetAllReply
{}
reply
=
&
pb
.
GetAllReply
{}
configs
,
err
:=
GetConfigureAll
()
configs
,
err
:=
GetConfigureAll
()
...
@@ -77,7 +86,10 @@ func (cs *ConfigureSevice) Select(ctx context.Context,
...
@@ -77,7 +86,10 @@ func (cs *ConfigureSevice) Select(ctx context.Context,
func
(
cs
*
ConfigureSevice
)
Update
(
ctx
context
.
Context
,
func
(
cs
*
ConfigureSevice
)
Update
(
ctx
context
.
Context
,
in
*
pb
.
UpdateRequest
)
(
reply
*
pb
.
ConfigureReply
,
err
error
)
{
in
*
pb
.
UpdateRequest
)
(
reply
*
pb
.
ConfigureReply
,
err
error
)
{
// 请求超时
if
err
=
helper
.
TimeOutCanceled
(
ctx
);
err
!=
nil
{
return
}
configure_add_struct
:=
vs
.
NewConfigureUpdateStruct
(
in
)
configure_add_struct
:=
vs
.
NewConfigureUpdateStruct
(
in
)
if
err
=
helper
.
Valiator
(
configure_add_struct
);
err
!=
nil
{
if
err
=
helper
.
Valiator
(
configure_add_struct
);
err
!=
nil
{
return
return
...
...
sevice/im_friend_request/main.go
View file @
03d51449
...
@@ -2,6 +2,9 @@ package im_friend_request
...
@@ -2,6 +2,9 @@ package im_friend_request
import
(
import
(
"context"
"context"
"im-microservice/helper"
"time"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/grpc/status"
"im-microservice/pb"
"im-microservice/pb"
...
@@ -14,6 +17,10 @@ type ImFriendService struct {
...
@@ -14,6 +17,10 @@ type ImFriendService struct {
}
}
func
(
fs
*
ImFriendService
)
All
(
ctx
context
.
Context
,
in
*
pb
.
ImFriendListReq
)
(
reply
*
pb
.
ImFriendListReply
,
err
error
)
{
func
(
fs
*
ImFriendService
)
All
(
ctx
context
.
Context
,
in
*
pb
.
ImFriendListReq
)
(
reply
*
pb
.
ImFriendListReply
,
err
error
)
{
// 请求超时
if
err
=
helper
.
TimeOutCanceled
(
ctx
);
err
!=
nil
{
return
}
// 添加用户是否存在
// 添加用户是否存在
if
_
,
err
=
im_user
.
GetImUserByAccid
(
in
.
Accid
);
err
!=
nil
{
if
_
,
err
=
im_user
.
GetImUserByAccid
(
in
.
Accid
);
err
!=
nil
{
err
=
status
.
Error
(
codes
.
NotFound
,
"用户不存在"
)
err
=
status
.
Error
(
codes
.
NotFound
,
"用户不存在"
)
...
@@ -38,6 +45,10 @@ func (fs *ImFriendService) All (ctx context.Context, in *pb.ImFriendListReq) (re
...
@@ -38,6 +45,10 @@ func (fs *ImFriendService) All (ctx context.Context, in *pb.ImFriendListReq) (re
}
}
func
(
fs
*
ImFriendService
)
Add
(
ctx
context
.
Context
,
in
*
pb
.
ImFriendAddReq
)
(
reply
*
pb
.
ImFriendEmptyReply
,
err
error
)
{
func
(
fs
*
ImFriendService
)
Add
(
ctx
context
.
Context
,
in
*
pb
.
ImFriendAddReq
)
(
reply
*
pb
.
ImFriendEmptyReply
,
err
error
)
{
// 请求超时
if
err
=
helper
.
TimeOutCanceled
(
ctx
);
err
!=
nil
{
return
}
// 添加用户是否存在
// 添加用户是否存在
if
_
,
err
=
im_user
.
GetImUserByAccid
(
in
.
Accid
);
err
!=
nil
{
if
_
,
err
=
im_user
.
GetImUserByAccid
(
in
.
Accid
);
err
!=
nil
{
err
=
status
.
Error
(
codes
.
NotFound
,
"用户不存在"
)
err
=
status
.
Error
(
codes
.
NotFound
,
"用户不存在"
)
...
@@ -71,6 +82,10 @@ func (fs *ImFriendService) Add (ctx context.Context,in *pb.ImFriendAddReq) (repl
...
@@ -71,6 +82,10 @@ func (fs *ImFriendService) Add (ctx context.Context,in *pb.ImFriendAddReq) (repl
}
}
func
(
fs
*
ImFriendService
)
Update
(
ctx
context
.
Context
,
in
*
pb
.
ImFriendUpdateReq
)
(
reply
*
pb
.
ImFriendEmptyReply
,
err
error
)
{
func
(
fs
*
ImFriendService
)
Update
(
ctx
context
.
Context
,
in
*
pb
.
ImFriendUpdateReq
)
(
reply
*
pb
.
ImFriendEmptyReply
,
err
error
)
{
// 请求超时
if
err
=
helper
.
TimeOutCanceled
(
ctx
);
err
!=
nil
{
return
}
if
err
=
Update
(
in
);
err
!=
nil
{
if
err
=
Update
(
in
);
err
!=
nil
{
err
=
status
.
Error
(
codes
.
Internal
,
err
.
Error
())
err
=
status
.
Error
(
codes
.
Internal
,
err
.
Error
())
return
return
...
...
sevice/im_user/im_user_db.go
View file @
03d51449
...
@@ -86,7 +86,6 @@ func UpdateImUser(accid string, m map[string]interface{}) (int64, error) {
...
@@ -86,7 +86,6 @@ func UpdateImUser(accid string, m map[string]interface{}) (int64, error) {
//获取用户信息
//获取用户信息
func
GetImUserByAccid
(
accid
string
)
(
db
.
ImUser
,
error
)
{
func
GetImUserByAccid
(
accid
string
)
(
db
.
ImUser
,
error
)
{
var
c_user
db
.
ImUser
var
c_user
db
.
ImUser
fmt
.
Println
(
db
.
MysqlClient
)
err
:=
db
.
MysqlClient
.
QueryTable
(
u_table_name
)
.
Filter
(
"accid"
,
accid
)
.
One
(
&
c_user
)
err
:=
db
.
MysqlClient
.
QueryTable
(
u_table_name
)
.
Filter
(
"accid"
,
accid
)
.
One
(
&
c_user
)
if
err
!=
nil
{
if
err
!=
nil
{
return
c_user
,
err
return
c_user
,
err
...
...
sevice/im_user_relationship/main.go
View file @
03d51449
...
@@ -17,7 +17,10 @@ type UserRelationshipService struct {
...
@@ -17,7 +17,10 @@ type UserRelationshipService struct {
func
(
us
*
UserRelationshipService
)
Add
(
ctx
context
.
Context
,
func
(
us
*
UserRelationshipService
)
Add
(
ctx
context
.
Context
,
in
*
pb
.
UserRelationshipAddRequest
)
(
reply
*
pb
.
UserRelationshipAddReply
,
err
error
)
{
in
*
pb
.
UserRelationshipAddRequest
)
(
reply
*
pb
.
UserRelationshipAddReply
,
err
error
)
{
// 请求超时
if
err
=
helper
.
TimeOutCanceled
(
ctx
);
err
!=
nil
{
return
}
//添加好友
//添加好友
if
err
=
AddUserRelationship
(
in
);
err
!=
nil
{
if
err
=
AddUserRelationship
(
in
);
err
!=
nil
{
return
return
...
@@ -36,7 +39,10 @@ func (us *UserRelationshipService) Add(ctx context.Context,
...
@@ -36,7 +39,10 @@ func (us *UserRelationshipService) Add(ctx context.Context,
func
(
us
*
UserRelationshipService
)
Delete
(
ctx
context
.
Context
,
func
(
us
*
UserRelationshipService
)
Delete
(
ctx
context
.
Context
,
in
*
pb
.
UserRelationshipDelRequest
)
(
reply
*
pb
.
UserRelationshipAddReply
,
err
error
)
{
in
*
pb
.
UserRelationshipDelRequest
)
(
reply
*
pb
.
UserRelationshipAddReply
,
err
error
)
{
// 请求超时
if
err
=
helper
.
TimeOutCanceled
(
ctx
);
err
!=
nil
{
return
}
// 删除好友
// 删除好友
if
err
=
DBDelete
(
in
);
err
!=
nil
{
if
err
=
DBDelete
(
in
);
err
!=
nil
{
return
return
...
@@ -55,7 +61,10 @@ func (us *UserRelationshipService) Delete(ctx context.Context,
...
@@ -55,7 +61,10 @@ func (us *UserRelationshipService) Delete(ctx context.Context,
func
(
us
*
UserRelationshipService
)
All
(
ctx
context
.
Context
,
func
(
us
*
UserRelationshipService
)
All
(
ctx
context
.
Context
,
in
*
pb
.
UserRelationshipListRequest
)
(
reply
*
pb
.
UserRelationshipListReply
,
err
error
)
{
in
*
pb
.
UserRelationshipListRequest
)
(
reply
*
pb
.
UserRelationshipListReply
,
err
error
)
{
// 请求超时
if
err
=
helper
.
TimeOutCanceled
(
ctx
);
err
!=
nil
{
return
}
results
,
err
:=
DBAll
(
in
)
results
,
err
:=
DBAll
(
in
)
if
err
!=
nil
{
if
err
!=
nil
{
err
=
status
.
Error
(
codes
.
Internal
,
err
.
Error
())
err
=
status
.
Error
(
codes
.
Internal
,
err
.
Error
())
...
@@ -73,7 +82,10 @@ func (us *UserRelationshipService) All(ctx context.Context,
...
@@ -73,7 +82,10 @@ func (us *UserRelationshipService) All(ctx context.Context,
func
(
us
*
UserRelationshipService
)
SetSpecialRelation
(
ctx
context
.
Context
,
func
(
us
*
UserRelationshipService
)
SetSpecialRelation
(
ctx
context
.
Context
,
in
*
pb
.
SetSpecialRelationReq
)
(
reply
*
pb
.
UserRelationshipAddReply
,
err
error
)
{
in
*
pb
.
SetSpecialRelationReq
)
(
reply
*
pb
.
UserRelationshipAddReply
,
err
error
)
{
// 请求超时
if
err
=
helper
.
TimeOutCanceled
(
ctx
);
err
!=
nil
{
return
}
if
err
=
SetSpecialRelationDb
(
in
);
err
!=
nil
{
if
err
=
SetSpecialRelationDb
(
in
);
err
!=
nil
{
err
=
status
.
Error
(
codes
.
Internal
,
err
.
Error
())
err
=
status
.
Error
(
codes
.
Internal
,
err
.
Error
())
return
return
...
@@ -85,6 +97,10 @@ func (us *UserRelationshipService) SetSpecialRelation(ctx context.Context,
...
@@ -85,6 +97,10 @@ func (us *UserRelationshipService) SetSpecialRelation(ctx context.Context,
func
(
us
*
UserRelationshipService
)
ListBlackAndMuteList
(
ctx
context
.
Context
,
func
(
us
*
UserRelationshipService
)
ListBlackAndMuteList
(
ctx
context
.
Context
,
in
*
pb
.
ListBlackAndMuteListReq
)
(
reply
*
pb
.
ListBlackAndMuteListReply
,
err
error
)
{
in
*
pb
.
ListBlackAndMuteListReq
)
(
reply
*
pb
.
ListBlackAndMuteListReply
,
err
error
)
{
// 请求超时
if
err
=
helper
.
TimeOutCanceled
(
ctx
);
err
!=
nil
{
return
}
blacklist
,
mutelist
,
err
:=
ListBlackAndMuteListDB
(
in
)
blacklist
,
mutelist
,
err
:=
ListBlackAndMuteListDB
(
in
)
if
err
!=
nil
{
if
err
!=
nil
{
err
=
status
.
Error
(
codes
.
Internal
,
err
.
Error
())
err
=
status
.
Error
(
codes
.
Internal
,
err
.
Error
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment