Merge remote-tracking branch 'origin/main'

This commit is contained in:
hailong
2021-05-26 19:53:03 +08:00
26 changed files with 3827 additions and 1 deletions
File diff suppressed because it is too large Load Diff
+159
View File
@@ -0,0 +1,159 @@
syntax = "proto3";
option go_package = "friend;friend";
package friend;
message CommonResp{
int32 errorCode = 1;
string errorMsg = 2;
}
message SearchFriendReq{
string uid = 1;
string OperationID = 2;
string Token = 3;
}
message SearchFriendResp{
int32 errorCode = 1;
string errorMsg = 2;
SearchFriendData Data = 3;
}
message SearchFriendData{
string uid = 1;
string icon = 2;
string name = 3;
int32 gender = 4;
string mobile = 5;
string birth = 6;
string email = 7;
string ex = 8;
string comment = 9;
int32 isFriend = 10;
int32 isInBlackList = 11;
}
message AddFriendReq{
string uid = 1;
string OperationID = 2;
string Token = 3;
string ReqMessage = 4;
}
message GetFriendApplyReq{
string OperationID = 1;
string Token = 2;
}
message GetFriendApplyResp{
int32 errorCode = 1;
string errorMsg = 2;
repeated ApplyUserInfo data = 4;
}
message ApplyUserInfo{
string uid = 1;
string name = 2;
string icon = 3;
int32 gender = 4;
string mobile = 5;
string birth = 6;
string email = 7;
string ex = 8;
int32 flag = 9;
string applyTime = 10;
string reqMessage = 11;
}
message getFriendListReq{
string OperationID = 1;
string Token = 2;
}
message getFriendListResp{
int32 errorCode = 1;
string errorMsg = 2;
repeated UserInfo data = 3;
}
message UserInfo{
string uid = 1;
string name = 3;
string icon = 2;
int32 gender = 4;
string mobile = 5;
string birth = 6;
string email = 7;
string ex = 8;
string comment = 9;
int32 isInBlackList = 10;
}
message AddBlacklistReq{
string uid = 1;
string OperationID = 2;
string Token = 3;
}
message RemoveBlacklistReq{
string uid = 1;
string OperationID = 2;
string Token = 3;
}
message GetBlacklistReq{
string OperationID = 1;
string token = 2;
}
message GetBlacklistResp{
int32 errorCode = 1;
string errorMsg = 2;
repeated UserInfo data = 3;
}
message IsInBlackListReq{
string sendUid = 1;
string receiveUid = 2;
string OperationID = 3;
}
message IsInBlackListResp{
int32 errorCode = 1;
string errorMsg = 2;
bool response = 3;
}
message DeleteFriendReq{
string uid = 1;
string OperationID = 2;
string Token = 3;
}
message AddedFriendReq{
string uid = 1;
int32 flag = 2;
string OperationID = 3;
string Token = 4;
}
message SetFriendCommentReq{
string uid = 1;
string operationID = 2;
string comment = 3;
string token = 4;
}
service friend{
rpc searchFriend(SearchFriendReq) returns(SearchFriendResp);
rpc addFriend(AddFriendReq) returns(CommonResp);
rpc getFriendApplyList(GetFriendApplyReq) returns(GetFriendApplyResp);
rpc getFriendList(getFriendListReq) returns(getFriendListResp);
rpc addBlacklist(AddBlacklistReq) returns(CommonResp);
rpc removeBlacklist(RemoveBlacklistReq) returns(CommonResp);
rpc isInBlackList(IsInBlackListReq) returns(IsInBlackListResp);
rpc getBlacklist(GetBlacklistReq) returns(GetBlacklistResp);
rpc deleteFriend(DeleteFriendReq) returns(CommonResp);
rpc addedFriend(AddedFriendReq) returns(CommonResp);
rpc setFriendComment(SetFriendCommentReq) returns(CommonResp);
}
+584
View File
@@ -0,0 +1,584 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: user/user.proto
package user
import (
context "context"
fmt "fmt"
proto "github.com/golang/protobuf/proto"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type CommonResp struct {
ErrorCode int32 `protobuf:"varint,1,opt,name=errorCode,proto3" json:"errorCode,omitempty"`
ErrorMsg string `protobuf:"bytes,2,opt,name=errorMsg,proto3" json:"errorMsg,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *CommonResp) Reset() { *m = CommonResp{} }
func (m *CommonResp) String() string { return proto.CompactTextString(m) }
func (*CommonResp) ProtoMessage() {}
func (*CommonResp) Descriptor() ([]byte, []int) {
return fileDescriptor_ed89022014131a74, []int{0}
}
func (m *CommonResp) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_CommonResp.Unmarshal(m, b)
}
func (m *CommonResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_CommonResp.Marshal(b, m, deterministic)
}
func (m *CommonResp) XXX_Merge(src proto.Message) {
xxx_messageInfo_CommonResp.Merge(m, src)
}
func (m *CommonResp) XXX_Size() int {
return xxx_messageInfo_CommonResp.Size(m)
}
func (m *CommonResp) XXX_DiscardUnknown() {
xxx_messageInfo_CommonResp.DiscardUnknown(m)
}
var xxx_messageInfo_CommonResp proto.InternalMessageInfo
func (m *CommonResp) GetErrorCode() int32 {
if m != nil {
return m.ErrorCode
}
return 0
}
func (m *CommonResp) GetErrorMsg() string {
if m != nil {
return m.ErrorMsg
}
return ""
}
type GetUserInfoReq struct {
UserIDList []string `protobuf:"bytes,1,rep,name=userIDList,proto3" json:"userIDList,omitempty"`
Token string `protobuf:"bytes,2,opt,name=token,proto3" json:"token,omitempty"`
OperationID string `protobuf:"bytes,3,opt,name=OperationID,proto3" json:"OperationID,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *GetUserInfoReq) Reset() { *m = GetUserInfoReq{} }
func (m *GetUserInfoReq) String() string { return proto.CompactTextString(m) }
func (*GetUserInfoReq) ProtoMessage() {}
func (*GetUserInfoReq) Descriptor() ([]byte, []int) {
return fileDescriptor_ed89022014131a74, []int{1}
}
func (m *GetUserInfoReq) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_GetUserInfoReq.Unmarshal(m, b)
}
func (m *GetUserInfoReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_GetUserInfoReq.Marshal(b, m, deterministic)
}
func (m *GetUserInfoReq) XXX_Merge(src proto.Message) {
xxx_messageInfo_GetUserInfoReq.Merge(m, src)
}
func (m *GetUserInfoReq) XXX_Size() int {
return xxx_messageInfo_GetUserInfoReq.Size(m)
}
func (m *GetUserInfoReq) XXX_DiscardUnknown() {
xxx_messageInfo_GetUserInfoReq.DiscardUnknown(m)
}
var xxx_messageInfo_GetUserInfoReq proto.InternalMessageInfo
func (m *GetUserInfoReq) GetUserIDList() []string {
if m != nil {
return m.UserIDList
}
return nil
}
func (m *GetUserInfoReq) GetToken() string {
if m != nil {
return m.Token
}
return ""
}
func (m *GetUserInfoReq) GetOperationID() string {
if m != nil {
return m.OperationID
}
return ""
}
type GetUserInfoResp struct {
ErrorCode int32 `protobuf:"varint,1,opt,name=errorCode,proto3" json:"errorCode,omitempty"`
ErrorMsg string `protobuf:"bytes,2,opt,name=errorMsg,proto3" json:"errorMsg,omitempty"`
Data []*UserInfo `protobuf:"bytes,3,rep,name=Data,proto3" json:"Data,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *GetUserInfoResp) Reset() { *m = GetUserInfoResp{} }
func (m *GetUserInfoResp) String() string { return proto.CompactTextString(m) }
func (*GetUserInfoResp) ProtoMessage() {}
func (*GetUserInfoResp) Descriptor() ([]byte, []int) {
return fileDescriptor_ed89022014131a74, []int{2}
}
func (m *GetUserInfoResp) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_GetUserInfoResp.Unmarshal(m, b)
}
func (m *GetUserInfoResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_GetUserInfoResp.Marshal(b, m, deterministic)
}
func (m *GetUserInfoResp) XXX_Merge(src proto.Message) {
xxx_messageInfo_GetUserInfoResp.Merge(m, src)
}
func (m *GetUserInfoResp) XXX_Size() int {
return xxx_messageInfo_GetUserInfoResp.Size(m)
}
func (m *GetUserInfoResp) XXX_DiscardUnknown() {
xxx_messageInfo_GetUserInfoResp.DiscardUnknown(m)
}
var xxx_messageInfo_GetUserInfoResp proto.InternalMessageInfo
func (m *GetUserInfoResp) GetErrorCode() int32 {
if m != nil {
return m.ErrorCode
}
return 0
}
func (m *GetUserInfoResp) GetErrorMsg() string {
if m != nil {
return m.ErrorMsg
}
return ""
}
func (m *GetUserInfoResp) GetData() []*UserInfo {
if m != nil {
return m.Data
}
return nil
}
type UserInfo struct {
Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Icon string `protobuf:"bytes,3,opt,name=icon,proto3" json:"icon,omitempty"`
Gender int32 `protobuf:"varint,4,opt,name=gender,proto3" json:"gender,omitempty"`
Mobile string `protobuf:"bytes,5,opt,name=mobile,proto3" json:"mobile,omitempty"`
Birth string `protobuf:"bytes,6,opt,name=birth,proto3" json:"birth,omitempty"`
Email string `protobuf:"bytes,7,opt,name=email,proto3" json:"email,omitempty"`
Ex string `protobuf:"bytes,8,opt,name=ex,proto3" json:"ex,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *UserInfo) Reset() { *m = UserInfo{} }
func (m *UserInfo) String() string { return proto.CompactTextString(m) }
func (*UserInfo) ProtoMessage() {}
func (*UserInfo) Descriptor() ([]byte, []int) {
return fileDescriptor_ed89022014131a74, []int{3}
}
func (m *UserInfo) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_UserInfo.Unmarshal(m, b)
}
func (m *UserInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_UserInfo.Marshal(b, m, deterministic)
}
func (m *UserInfo) XXX_Merge(src proto.Message) {
xxx_messageInfo_UserInfo.Merge(m, src)
}
func (m *UserInfo) XXX_Size() int {
return xxx_messageInfo_UserInfo.Size(m)
}
func (m *UserInfo) XXX_DiscardUnknown() {
xxx_messageInfo_UserInfo.DiscardUnknown(m)
}
var xxx_messageInfo_UserInfo proto.InternalMessageInfo
func (m *UserInfo) GetUid() string {
if m != nil {
return m.Uid
}
return ""
}
func (m *UserInfo) GetName() string {
if m != nil {
return m.Name
}
return ""
}
func (m *UserInfo) GetIcon() string {
if m != nil {
return m.Icon
}
return ""
}
func (m *UserInfo) GetGender() int32 {
if m != nil {
return m.Gender
}
return 0
}
func (m *UserInfo) GetMobile() string {
if m != nil {
return m.Mobile
}
return ""
}
func (m *UserInfo) GetBirth() string {
if m != nil {
return m.Birth
}
return ""
}
func (m *UserInfo) GetEmail() string {
if m != nil {
return m.Email
}
return ""
}
func (m *UserInfo) GetEx() string {
if m != nil {
return m.Ex
}
return ""
}
type LogoutReq struct {
OperationID string `protobuf:"bytes,1,opt,name=OperationID,proto3" json:"OperationID,omitempty"`
Token string `protobuf:"bytes,2,opt,name=token,proto3" json:"token,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *LogoutReq) Reset() { *m = LogoutReq{} }
func (m *LogoutReq) String() string { return proto.CompactTextString(m) }
func (*LogoutReq) ProtoMessage() {}
func (*LogoutReq) Descriptor() ([]byte, []int) {
return fileDescriptor_ed89022014131a74, []int{4}
}
func (m *LogoutReq) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_LogoutReq.Unmarshal(m, b)
}
func (m *LogoutReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_LogoutReq.Marshal(b, m, deterministic)
}
func (m *LogoutReq) XXX_Merge(src proto.Message) {
xxx_messageInfo_LogoutReq.Merge(m, src)
}
func (m *LogoutReq) XXX_Size() int {
return xxx_messageInfo_LogoutReq.Size(m)
}
func (m *LogoutReq) XXX_DiscardUnknown() {
xxx_messageInfo_LogoutReq.DiscardUnknown(m)
}
var xxx_messageInfo_LogoutReq proto.InternalMessageInfo
func (m *LogoutReq) GetOperationID() string {
if m != nil {
return m.OperationID
}
return ""
}
func (m *LogoutReq) GetToken() string {
if m != nil {
return m.Token
}
return ""
}
type UpdateUserInfoReq struct {
Icon string `protobuf:"bytes,1,opt,name=icon,proto3" json:"icon,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Gender int32 `protobuf:"varint,3,opt,name=gender,proto3" json:"gender,omitempty"`
Mobile string `protobuf:"bytes,4,opt,name=mobile,proto3" json:"mobile,omitempty"`
Birth string `protobuf:"bytes,5,opt,name=birth,proto3" json:"birth,omitempty"`
Email string `protobuf:"bytes,6,opt,name=email,proto3" json:"email,omitempty"`
Ex string `protobuf:"bytes,7,opt,name=ex,proto3" json:"ex,omitempty"`
Token string `protobuf:"bytes,8,opt,name=token,proto3" json:"token,omitempty"`
OperationID string `protobuf:"bytes,9,opt,name=OperationID,proto3" json:"OperationID,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *UpdateUserInfoReq) Reset() { *m = UpdateUserInfoReq{} }
func (m *UpdateUserInfoReq) String() string { return proto.CompactTextString(m) }
func (*UpdateUserInfoReq) ProtoMessage() {}
func (*UpdateUserInfoReq) Descriptor() ([]byte, []int) {
return fileDescriptor_ed89022014131a74, []int{5}
}
func (m *UpdateUserInfoReq) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_UpdateUserInfoReq.Unmarshal(m, b)
}
func (m *UpdateUserInfoReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_UpdateUserInfoReq.Marshal(b, m, deterministic)
}
func (m *UpdateUserInfoReq) XXX_Merge(src proto.Message) {
xxx_messageInfo_UpdateUserInfoReq.Merge(m, src)
}
func (m *UpdateUserInfoReq) XXX_Size() int {
return xxx_messageInfo_UpdateUserInfoReq.Size(m)
}
func (m *UpdateUserInfoReq) XXX_DiscardUnknown() {
xxx_messageInfo_UpdateUserInfoReq.DiscardUnknown(m)
}
var xxx_messageInfo_UpdateUserInfoReq proto.InternalMessageInfo
func (m *UpdateUserInfoReq) GetIcon() string {
if m != nil {
return m.Icon
}
return ""
}
func (m *UpdateUserInfoReq) GetName() string {
if m != nil {
return m.Name
}
return ""
}
func (m *UpdateUserInfoReq) GetGender() int32 {
if m != nil {
return m.Gender
}
return 0
}
func (m *UpdateUserInfoReq) GetMobile() string {
if m != nil {
return m.Mobile
}
return ""
}
func (m *UpdateUserInfoReq) GetBirth() string {
if m != nil {
return m.Birth
}
return ""
}
func (m *UpdateUserInfoReq) GetEmail() string {
if m != nil {
return m.Email
}
return ""
}
func (m *UpdateUserInfoReq) GetEx() string {
if m != nil {
return m.Ex
}
return ""
}
func (m *UpdateUserInfoReq) GetToken() string {
if m != nil {
return m.Token
}
return ""
}
func (m *UpdateUserInfoReq) GetOperationID() string {
if m != nil {
return m.OperationID
}
return ""
}
func init() {
proto.RegisterType((*CommonResp)(nil), "user.CommonResp")
proto.RegisterType((*GetUserInfoReq)(nil), "user.GetUserInfoReq")
proto.RegisterType((*GetUserInfoResp)(nil), "user.GetUserInfoResp")
proto.RegisterType((*UserInfo)(nil), "user.UserInfo")
proto.RegisterType((*LogoutReq)(nil), "user.LogoutReq")
proto.RegisterType((*UpdateUserInfoReq)(nil), "user.UpdateUserInfoReq")
}
func init() { proto.RegisterFile("user/user.proto", fileDescriptor_ed89022014131a74) }
var fileDescriptor_ed89022014131a74 = []byte{
// 416 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x53, 0x4d, 0x8b, 0xd4, 0x40,
0x10, 0xa5, 0x27, 0x1f, 0x9b, 0x54, 0x20, 0xbb, 0x16, 0xab, 0x36, 0x83, 0x48, 0xc8, 0x29, 0xa7,
0x15, 0xd6, 0x9b, 0x7b, 0x73, 0x06, 0x65, 0x60, 0x45, 0x08, 0xec, 0xc5, 0x5b, 0xc6, 0x94, 0x99,
0xe0, 0x24, 0x1d, 0x3b, 0x3d, 0x30, 0x37, 0xff, 0x92, 0xff, 0xc8, 0xbf, 0x22, 0xdd, 0xc9, 0x4c,
0x32, 0x33, 0xd1, 0x8b, 0x97, 0x50, 0xef, 0x75, 0xa8, 0xaa, 0xf7, 0xaa, 0x0a, 0xae, 0x77, 0x2d,
0xc9, 0x37, 0xfa, 0x73, 0xd7, 0x48, 0xa1, 0x04, 0xda, 0x3a, 0x8e, 0x3f, 0x00, 0x2c, 0x44, 0x55,
0x89, 0x3a, 0xa5, 0xb6, 0xc1, 0x57, 0xe0, 0x93, 0x94, 0x42, 0x2e, 0x44, 0x4e, 0x9c, 0x45, 0x2c,
0x71, 0xd2, 0x81, 0xc0, 0x39, 0x78, 0x06, 0x7c, 0x6a, 0x0b, 0x3e, 0x8b, 0x58, 0xe2, 0xa7, 0x47,
0x1c, 0x6f, 0x20, 0xfc, 0x48, 0xea, 0xa9, 0x25, 0xb9, 0xaa, 0xbf, 0x89, 0x94, 0x7e, 0xe0, 0x6b,
0x00, 0x5d, 0x61, 0xb5, 0x7c, 0x2c, 0x5b, 0xc5, 0x59, 0x64, 0x25, 0x7e, 0x3a, 0x62, 0xf0, 0x16,
0x1c, 0x25, 0xbe, 0x53, 0xdd, 0xa7, 0xea, 0x00, 0x46, 0x10, 0x7c, 0x6e, 0x48, 0x66, 0xaa, 0x14,
0xf5, 0x6a, 0xc9, 0x2d, 0xf3, 0x36, 0xa6, 0x62, 0x01, 0xd7, 0x27, 0x95, 0xfe, 0xa7, 0x6d, 0x8c,
0xc1, 0x5e, 0x66, 0x2a, 0xe3, 0x56, 0x64, 0x25, 0xc1, 0x7d, 0x78, 0x67, 0xfc, 0x39, 0xe6, 0x36,
0x6f, 0xf1, 0x2f, 0x06, 0xde, 0x81, 0xc2, 0x1b, 0xb0, 0x76, 0x65, 0x6e, 0x8a, 0xf8, 0xa9, 0x0e,
0x11, 0xc1, 0xae, 0xb3, 0x8a, 0xfa, 0xd4, 0x26, 0xd6, 0x5c, 0xf9, 0x55, 0xd4, 0x7d, 0xfb, 0x26,
0xc6, 0x17, 0xe0, 0x16, 0x54, 0xe7, 0x24, 0xb9, 0x6d, 0x3a, 0xec, 0x91, 0xe6, 0x2b, 0xb1, 0x2e,
0xb7, 0xc4, 0x1d, 0xf3, 0x77, 0x8f, 0xb4, 0x3f, 0xeb, 0x52, 0xaa, 0x0d, 0x77, 0x3b, 0x7f, 0x0c,
0xd0, 0x2c, 0x55, 0x59, 0xb9, 0xe5, 0x57, 0x1d, 0x6b, 0x00, 0x86, 0x30, 0xa3, 0x3d, 0xf7, 0x0c,
0x35, 0xa3, 0x7d, 0xbc, 0x00, 0xff, 0x51, 0x14, 0x62, 0xa7, 0xf4, 0x20, 0xce, 0x2c, 0x65, 0x17,
0x96, 0x4e, 0x8f, 0x22, 0xfe, 0xcd, 0xe0, 0xd9, 0x53, 0x93, 0x67, 0x8a, 0xc6, 0x63, 0x3d, 0x48,
0x63, 0x23, 0x69, 0x53, 0x16, 0x0c, 0x72, 0xad, 0xbf, 0xc8, 0xb5, 0xa7, 0xe5, 0x3a, 0x93, 0x72,
0xdd, 0x4b, 0xb9, 0x57, 0x07, 0xb9, 0x43, 0xff, 0xde, 0x3f, 0x56, 0xc9, 0xbf, 0xd0, 0x7d, 0xff,
0x13, 0xcc, 0x11, 0xe0, 0x3b, 0x08, 0x8a, 0x61, 0xa5, 0xf0, 0xb6, 0x5b, 0x83, 0xd3, 0x7d, 0x9e,
0x3f, 0x9f, 0x60, 0xdb, 0x06, 0x1f, 0x20, 0x3c, 0x35, 0x09, 0x5f, 0xf6, 0x5b, 0x74, 0x6e, 0xdd,
0xfc, 0xa6, 0x7b, 0x18, 0xee, 0xed, 0x7d, 0xf0, 0xc5, 0xd7, 0xd4, 0x83, 0xfe, 0xac, 0x5d, 0x73,
0x97, 0x6f, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, 0xf8, 0x6d, 0x34, 0xa2, 0xaa, 0x03, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
// UserClient is the client API for User service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type UserClient interface {
GetUserInfo(ctx context.Context, in *GetUserInfoReq, opts ...grpc.CallOption) (*GetUserInfoResp, error)
UpdateUserInfo(ctx context.Context, in *UpdateUserInfoReq, opts ...grpc.CallOption) (*CommonResp, error)
}
type userClient struct {
cc *grpc.ClientConn
}
func NewUserClient(cc *grpc.ClientConn) UserClient {
return &userClient{cc}
}
func (c *userClient) GetUserInfo(ctx context.Context, in *GetUserInfoReq, opts ...grpc.CallOption) (*GetUserInfoResp, error) {
out := new(GetUserInfoResp)
err := c.cc.Invoke(ctx, "/user.user/getUserInfo", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *userClient) UpdateUserInfo(ctx context.Context, in *UpdateUserInfoReq, opts ...grpc.CallOption) (*CommonResp, error) {
out := new(CommonResp)
err := c.cc.Invoke(ctx, "/user.user/UpdateUserInfo", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// UserServer is the server API for User service.
type UserServer interface {
GetUserInfo(context.Context, *GetUserInfoReq) (*GetUserInfoResp, error)
UpdateUserInfo(context.Context, *UpdateUserInfoReq) (*CommonResp, error)
}
// UnimplementedUserServer can be embedded to have forward compatible implementations.
type UnimplementedUserServer struct {
}
func (*UnimplementedUserServer) GetUserInfo(ctx context.Context, req *GetUserInfoReq) (*GetUserInfoResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetUserInfo not implemented")
}
func (*UnimplementedUserServer) UpdateUserInfo(ctx context.Context, req *UpdateUserInfoReq) (*CommonResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateUserInfo not implemented")
}
func RegisterUserServer(s *grpc.Server, srv UserServer) {
s.RegisterService(&_User_serviceDesc, srv)
}
func _User_GetUserInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetUserInfoReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UserServer).GetUserInfo(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/user.user/GetUserInfo",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UserServer).GetUserInfo(ctx, req.(*GetUserInfoReq))
}
return interceptor(ctx, in, info, handler)
}
func _User_UpdateUserInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdateUserInfoReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UserServer).UpdateUserInfo(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/user.user/UpdateUserInfo",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UserServer).UpdateUserInfo(ctx, req.(*UpdateUserInfoReq))
}
return interceptor(ctx, in, info, handler)
}
var _User_serviceDesc = grpc.ServiceDesc{
ServiceName: "user.user",
HandlerType: (*UserServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "getUserInfo",
Handler: _User_GetUserInfo_Handler,
},
{
MethodName: "UpdateUserInfo",
Handler: _User_UpdateUserInfo_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "user/user.proto",
}
+52
View File
@@ -0,0 +1,52 @@
syntax = "proto3";
option go_package = "user;user";
package user;
message CommonResp{
int32 errorCode = 1;
string errorMsg = 2;
}
message GetUserInfoReq{
repeated string userIDList = 1;
string token = 2;
string OperationID = 3;
}
message GetUserInfoResp{
int32 errorCode = 1;
string errorMsg = 2;
repeated UserInfo Data = 3;
}
message UserInfo{
string uid = 1;
string name = 2;
string icon = 3;
int32 gender = 4;
string mobile = 5;
string birth = 6;
string email = 7;
string ex = 8;
}
message LogoutReq{
string OperationID = 1;
string token = 2;
}
message UpdateUserInfoReq{
string icon = 1;
string name = 2;
int32 gender = 3;
string mobile = 4;
string birth = 5;
string email = 6;
string ex = 7;
string token = 8;
string OperationID = 9;
}
service user {
rpc getUserInfo(GetUserInfoReq) returns(GetUserInfoResp);
rpc UpdateUserInfo(UpdateUserInfoReq) returns(CommonResp);
}
+27
View File
@@ -0,0 +1,27 @@
.PHONY: all build run gotool install clean help
BINARY_NAME=open_im_friend
BIN_DIR=../../../bin/
LAN_FILE=.go
GO_FILE:=${BINARY_NAME}${LAN_FILE}
all: gotool build
build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${BINARY_NAME} ${GO_FILE}
run:
@go run ./
gotool:
go fmt ./
go vet ./
install:
make build
mv ${BINARY_NAME} ${BIN_DIR}
clean:
@if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi
+28
View File
@@ -0,0 +1,28 @@
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/db/mysql_model/im_mysql_model"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"Open_IM/src/utils"
"context"
)
func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlacklistReq) (*pbFriend.CommonResp, error) {
log.Info(req.Token, req.OperationID, "rpc add blacklist is server,args=%s", req.String())
//Parse token, to find current user information
claims, err := utils.ParseToken(req.Token)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
} else {
err := im_mysql_model.InsertInToUserBlackList(claims.UID, req.Uid)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,Failed to add blacklist", err.Error())
return &pbFriend.CommonResp{ErrorCode: config.ErrMysql.ErrCode, ErrorMsg: config.ErrMysql.ErrMsg}, nil
}
}
log.Info(req.Token, req.OperationID, "rpc add blacklist success return,uid=%s", req.Uid)
return &pbFriend.CommonResp{}, nil
}
+47
View File
@@ -0,0 +1,47 @@
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/constant"
"Open_IM/src/common/db/mysql_model/im_mysql_model"
"Open_IM/src/common/log"
pbChat "Open_IM/src/proto/chat"
pbFriend "Open_IM/src/proto/friend"
"Open_IM/src/push/logic"
"Open_IM/src/utils"
"context"
"fmt"
)
func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq) (*pbFriend.CommonResp, error) {
log.Info(req.Token, req.OperationID, "rpc add friend is server,userid=%s", req.Uid)
//Parse token, to find current user information
claims, err := utils.ParseToken(req.Token)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
}
//Establish a relationship in the friend request table
err = im_mysql_model.InsertIntoFriendReq(claims.UID, req.Uid, constant.NotFriendFlag, req.ReqMessage)
if err != nil {
log.Error(req.Token, req.OperationID, fmt.Sprintf("err=%s,create friend request ship failed", err.Error()))
return &pbFriend.CommonResp{ErrorCode: config.ErrAddFriend.ErrCode, ErrorMsg: config.ErrAddFriend.ErrMsg}, nil
}
log.Info(req.Token, req.OperationID, "rpc add friend is success return,uid=%s", req.Uid)
//Push message when add friend successfully
senderInfo, errSend := im_mysql_model.FindUserByUID(claims.UID)
receiverInfo, errReceive := im_mysql_model.FindUserByUID(req.Uid)
if errSend == nil && errReceive == nil {
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
SendID: senderInfo.UID,
RecvID: receiverInfo.UID,
Content: senderInfo.Name + " asked to add you as a friend",
SendTime: utils.GetCurrentTimestampBySecond(),
MsgFrom: constant.SysMsgType,
ContentType: constant.AddFriendTip,
SessionType: constant.SingleChatType,
OperationID: req.OperationID,
})
}
return &pbFriend.CommonResp{}, nil
}
@@ -0,0 +1,58 @@
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/constant"
"Open_IM/src/common/db/mysql_model/im_mysql_model"
"Open_IM/src/common/log"
pbChat "Open_IM/src/proto/chat"
pbFriend "Open_IM/src/proto/friend"
"Open_IM/src/push/logic"
"Open_IM/src/utils"
"context"
)
func (s *friendServer) AddedFriend(ctx context.Context, req *pbFriend.AddedFriendReq) (*pbFriend.CommonResp, error) {
log.Info(req.Token, req.OperationID, "rpc add friend response is server,args=%s", req.String())
//Parse token, to find current user information
claims, err := utils.ParseToken(req.Token)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
}
err = im_mysql_model.UpdateFriendRelationshipToFriendReq(req.Uid, claims.UID, req.Flag)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,update friend request table failed", err.Error())
return &pbFriend.CommonResp{ErrorCode: config.ErrMysql.ErrCode, ErrorMsg: config.ErrMysql.ErrMsg}, nil
}
log.Info(req.Token, req.OperationID, "rpc add friend response success return,userid=%s,flag=%d", req.Uid, req.Flag)
//Change the status of the friend request form
if req.Flag == 1 {
//Establish two single friendship
err = im_mysql_model.InsertToFriend(claims.UID, req.Uid, req.Flag)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,create friendship failed", err.Error())
return &pbFriend.CommonResp{ErrorCode: config.ErrAddFriend.ErrCode, ErrorMsg: config.ErrAddFriend.ErrMsg}, nil
}
err = im_mysql_model.InsertToFriend(req.Uid, claims.UID, req.Flag)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,create friendship failed", err.Error())
return &pbFriend.CommonResp{ErrorCode: config.ErrAddFriend.ErrCode, ErrorMsg: config.ErrAddFriend.ErrMsg}, nil
}
//Push message when establish friends successfully
senderInfo, errSend := im_mysql_model.FindUserByUID(claims.UID)
if errSend == nil {
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
SendID: claims.UID,
RecvID: req.Uid,
Content: senderInfo.Name + " agreed to add you as a friend.",
SendTime: utils.GetCurrentTimestampBySecond(),
MsgFrom: constant.SysMsgType, //Notification message identification
ContentType: constant.AgreeAddFriendTip, //Add friend flag
SessionType: constant.SingleChatType,
OperationID: req.OperationID,
})
}
}
return &pbFriend.CommonResp{}, nil
}
+27
View File
@@ -0,0 +1,27 @@
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/db/mysql_model/im_mysql_model"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"Open_IM/src/utils"
"context"
)
func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFriendReq) (*pbFriend.CommonResp, error) {
log.Info(req.Token, req.OperationID, "rpc delete friend is server,args=%s", req.String())
//Parse token, to find current user information
claims, err := utils.ParseToken(req.Token)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
}
err = im_mysql_model.DeleteSingleFriendInfo(claims.UID, req.Uid)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,delete friend failed", err.Error())
return &pbFriend.CommonResp{ErrorCode: config.ErrMysql.ErrCode, ErrorMsg: config.ErrMysql.ErrMsg}, nil
}
log.Info(req.Token, req.OperationID, "rpc delete friend success return")
return &pbFriend.CommonResp{}, nil
}
+55
View File
@@ -0,0 +1,55 @@
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/db/mysql_model/im_mysql_model"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"Open_IM/src/utils"
"context"
)
func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlacklistReq) (*pbFriend.GetBlacklistResp, error) {
log.Info(req.Token, req.OperationID, "rpc get blacklist is server,args=%s", req.String())
var (
userInfoList []*pbFriend.UserInfo
comment string
)
//Parse token, to find current user information
claims, err := utils.ParseToken(req.Token)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
return &pbFriend.GetBlacklistResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
}
blackListInfo, err := im_mysql_model.GetBlackListByUID(claims.UID)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s get blacklist failed", err.Error())
return &pbFriend.GetBlacklistResp{ErrorCode: config.ErrGetBlackList.ErrCode, ErrorMsg: config.ErrGetBlackList.ErrMsg}, nil
}
for _, blackUser := range blackListInfo {
var blackUserInfo pbFriend.UserInfo
//Find black user information
us, err := im_mysql_model.FindUserByUID(blackUser.BlockId)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s search black list userInfo failed", err.Error())
continue
}
friendShip, err := im_mysql_model.FindFriendRelationshipFromFriend(claims.UID, blackUser.BlockId)
if err == nil {
comment = friendShip.Comment
}
blackUserInfo.Uid = us.UID
blackUserInfo.Icon = us.Icon
blackUserInfo.Name = us.Name
blackUserInfo.Gender = us.Gender
blackUserInfo.Mobile = us.Mobile
blackUserInfo.Birth = us.Birth
blackUserInfo.Email = us.Email
blackUserInfo.Ex = us.Ex
blackUserInfo.Comment = comment
userInfoList = append(userInfoList, &blackUserInfo)
}
log.Info(req.Token, req.OperationID, "rpc get blacklist success return")
return &pbFriend.GetBlacklistResp{Data: userInfoList}, nil
}
@@ -0,0 +1,58 @@
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/db/mysql_model/im_mysql_model"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"Open_IM/src/utils"
"context"
"fmt"
"strconv"
)
func (s *friendServer) GetFriendApplyList(ctx context.Context, req *pbFriend.GetFriendApplyReq) (*pbFriend.GetFriendApplyResp, error) {
log.Info(req.Token, req.OperationID, "rpc get friend apply list is server,args=%s", req.String())
var appleUserList []*pbFriend.ApplyUserInfo
//Parse token, to find current user information
claims, err := utils.ParseToken(req.Token)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
return &pbFriend.GetFriendApplyResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
}
// Find the current user friend applications received
ApplyUsersInfo, err := im_mysql_model.FindFriendsApplyFromFriendReq(claims.UID)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,search applyInfo failed", err.Error())
return &pbFriend.GetFriendApplyResp{ErrorCode: config.ErrMysql.ErrCode, ErrorMsg: config.ErrMysql.ErrMsg}, nil
}
for _, applyUserInfo := range ApplyUsersInfo {
var userInfo pbFriend.ApplyUserInfo
//Find friend application status
friendReqStatus, err := im_mysql_model.FindFriendRelationshipFromFriendReq(applyUserInfo.ReqId, applyUserInfo.UserId)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,search friendRelationshipStatus failed", err.Error())
} else {
userInfo.Flag = friendReqStatus.Flag
userInfo.ReqMessage = friendReqStatus.ReqMessage
userInfo.ApplyTime = strconv.FormatInt(friendReqStatus.CreateTime.Unix(), 10)
}
//Find user information
us, err := im_mysql_model.FindUserByUID(applyUserInfo.ReqId)
if err != nil {
log.Error(req.Token, req.OperationID, fmt.Sprintf("err=%s,search userInfo failed", err.Error()))
} else {
userInfo.Uid = us.UID
userInfo.Icon = us.Icon
userInfo.Name = us.Name
userInfo.Gender = us.Gender
userInfo.Mobile = us.Mobile
userInfo.Birth = us.Birth
userInfo.Email = us.Email
userInfo.Ex = us.Ex
appleUserList = append(appleUserList, &userInfo)
}
}
log.Info(req.Token, req.OperationID, fmt.Sprintf("rpc get friendapplylist success return"))
return &pbFriend.GetFriendApplyResp{Data: appleUserList}, nil
}
+59
View File
@@ -0,0 +1,59 @@
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/constant"
"Open_IM/src/common/db/mysql_model/im_mysql_model"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"Open_IM/src/utils"
"context"
"fmt"
)
func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFriendListReq) (*pbFriend.GetFriendListResp, error) {
log.Info(req.Token, req.OperationID, "rpc get friend list is server,args=%s", req.String())
var userInfoList []*pbFriend.UserInfo
//Parse token, to find current user information
claims, err := utils.ParseToken(req.Token)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
return &pbFriend.GetFriendListResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
}
friends, err := im_mysql_model.FindUserInfoFromFriend(claims.UID)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s search friendInfo failed", err.Error())
return &pbFriend.GetFriendListResp{ErrorCode: config.ErrSearchUserInfo.ErrCode, ErrorMsg: config.ErrSearchUserInfo.ErrMsg}, nil
}
for _, friendUser := range friends {
var friendUserInfo pbFriend.UserInfo
//find user is in blackList
err = im_mysql_model.FindRelationshipFromBlackList(claims.UID, friendUser.FriendId)
if err == nil {
friendUserInfo.IsInBlackList = constant.BlackListFlag
} else {
friendUserInfo.IsInBlackList = 0
}
//Find user information
us, err := im_mysql_model.FindUserByUID(friendUser.FriendId)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s search userInfo failed", err.Error())
} else {
friendUserInfo.Uid = friendUser.FriendId
friendUserInfo.Comment = friendUser.Comment
friendUserInfo.Icon = us.Icon
friendUserInfo.Name = us.Name
friendUserInfo.Gender = us.Gender
friendUserInfo.Mobile = us.Mobile
friendUserInfo.Birth = us.Birth
friendUserInfo.Email = us.Email
friendUserInfo.Ex = us.Ex
userInfoList = append(userInfoList, &friendUserInfo)
}
}
log.Info(req.Token, req.OperationID, fmt.Sprintf("rpc get friend list success return"))
return &pbFriend.GetFriendListResp{Data: userInfoList}, nil
}
+22
View File
@@ -0,0 +1,22 @@
package friend
import (
"Open_IM/src/common/db/mysql_model/im_mysql_model"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"context"
"fmt"
)
func (s *friendServer) IsInBlackList(ctx context.Context, req *pbFriend.IsInBlackListReq) (*pbFriend.IsInBlackListResp, error) {
log.InfoByArgs("rpc is in blacklist is server,args=%s", req.String())
var isInBlacklist = false
err := im_mysql_model.FindRelationshipFromBlackList(req.ReceiveUid, req.SendUid)
if err != nil {
log.Error("", req.OperationID, "err=%s,", err.Error())
} else {
isInBlacklist = true
}
log.InfoByArgs(fmt.Sprintf("rpc is in blackList success return"))
return &pbFriend.IsInBlackListResp{Response: isInBlacklist}, nil
}
+27
View File
@@ -0,0 +1,27 @@
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/db/mysql_model/im_mysql_model"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"Open_IM/src/utils"
"context"
)
func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.RemoveBlacklistReq) (*pbFriend.CommonResp, error) {
log.Info(req.Token, req.OperationID, "rpc remove blacklist is server,userid=%s", req.Uid)
//Parse token, to find current user information
claims, err := utils.ParseToken(req.Token)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
}
err = im_mysql_model.RemoveBlackList(claims.UID, req.Uid)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,remove blacklist failed", err.Error())
return &pbFriend.CommonResp{ErrorCode: config.ErrMysql.ErrCode, ErrorMsg: config.ErrMysql.ErrMsg}, nil
}
log.Info(req.Token, req.OperationID, "rpc remove blacklist success return,userid=%s", req.Uid)
return &pbFriend.CommonResp{}, nil
}
+111
View File
@@ -0,0 +1,111 @@
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/constant"
"Open_IM/src/common/db/mysql_model/im_mysql_model"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"Open_IM/src/utils"
"context"
"fmt"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"google.golang.org/grpc"
"net"
"strconv"
"strings"
)
type friendServer struct {
rpcPort int
rpcRegisterName string
etcdSchema string
etcdAddr []string
}
func NewFriendServer(port int) *friendServer {
return &friendServer{
rpcPort: port,
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
etcdSchema: config.Config.Etcd.EtcdSchema,
etcdAddr: config.Config.Etcd.EtcdAddr,
}
}
func (s *friendServer) Run() {
log.Info("", "", fmt.Sprintf("rpc friend init...."))
ip := utils.ServerIP
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
//listener network
listener, err := net.Listen("tcp", registerAddress)
if err != nil {
log.InfoByArgs(fmt.Sprintf("Failed to listen rpc friend network,err=%s", err.Error()))
return
}
log.Info("", "", "listen network success, address = %s", registerAddress)
defer listener.Close()
//grpc server
srv := grpc.NewServer()
defer srv.GracefulStop()
//User friend related services register to etcd
pbFriend.RegisterFriendServer(srv, s)
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
if err != nil {
log.ErrorByArgs("register rpc fiend service to etcd failed,err=%s", err.Error())
return
}
err = srv.Serve(listener)
if err != nil {
log.ErrorByArgs("listen rpc friend error,err=%s", err.Error())
return
}
}
func (s *friendServer) SearchFriend(ctx context.Context, req *pbFriend.SearchFriendReq) (*pbFriend.SearchFriendResp, error) {
log.Info(req.Token, req.OperationID, fmt.Sprintf("rpc search user is server,args=%s", req.String()))
var (
isInBlackList int32
isFriend int32
comment string
)
//Parse token, to find current user information
claims, err := utils.ParseToken(req.Token)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
return &pbFriend.SearchFriendResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
}
friendShip, err := im_mysql_model.FindFriendRelationshipFromFriend(claims.UID, req.Uid)
if err == nil {
isFriend = constant.FriendFlag
comment = friendShip.Comment
}
friendUserInfo, err := im_mysql_model.FindUserByUID(req.Uid)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,no this user", err.Error())
return &pbFriend.SearchFriendResp{ErrorCode: config.ErrSearchUserInfo.ErrCode, ErrorMsg: config.ErrSearchUserInfo.ErrMsg}, nil
}
err = im_mysql_model.FindRelationshipFromBlackList(claims.UID, req.Uid)
if err == nil {
isInBlackList = constant.BlackListFlag
}
log.Info(req.Token, req.OperationID, "rpc search friend success return")
return &pbFriend.SearchFriendResp{
ErrorCode: 0,
ErrorMsg: "",
Data: &pbFriend.SearchFriendData{
Uid: friendUserInfo.UID,
Icon: friendUserInfo.Icon,
Name: friendUserInfo.Name,
Gender: friendUserInfo.Gender,
Mobile: friendUserInfo.Mobile,
Birth: friendUserInfo.Birth,
Email: friendUserInfo.Email,
Ex: friendUserInfo.Ex,
Comment: comment,
IsFriend: isFriend,
IsInBlackList: isInBlackList,
},
}, nil
}
@@ -0,0 +1,27 @@
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/db/mysql_model/im_mysql_model"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"Open_IM/src/utils"
"context"
)
func (s *friendServer) SetFriendComment(ctx context.Context, req *pbFriend.SetFriendCommentReq) (*pbFriend.CommonResp, error) {
log.Info(req.Token, req.OperationID, "rpc set friend comment is server,params=%s", req.String())
//Parse token, to find current user information
claims, err := utils.ParseToken(req.Token)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
}
err = im_mysql_model.UpdateFriendComment(claims.UID, req.Uid, req.Comment)
if err != nil {
log.Error(req.Token, req.OperationID, "set friend comment failed,err=%s", err.Error())
return &pbFriend.CommonResp{ErrorCode: config.ErrSetFriendComment.ErrCode, ErrorMsg: config.ErrSetFriendComment.ErrMsg}, nil
}
log.Info(req.Token, req.OperationID, "rpc set friend comment is success return")
return &pbFriend.CommonResp{}, nil
}
+14
View File
@@ -0,0 +1,14 @@
package main
import (
"Open_IM/src/rpc/friend/friend"
"flag"
)
func main() {
rpcPort := flag.Int("port", 10200, "get RpcFriendPort from cmd,default 12000 as port")
flag.Parse()
rpcServer := friend.NewFriendServer(*rpcPort)
rpcServer.Run()
}
+27
View File
@@ -0,0 +1,27 @@
.PHONY: all build run gotool install clean help
BINARY_NAME=open_im_user
BIN_DIR=../../../bin/
LAN_FILE=.go
GO_FILE:=${BINARY_NAME}${LAN_FILE}
all: gotool build
build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${BINARY_NAME} ${GO_FILE}
run:
@go run ./
gotool:
go fmt ./
go vet ./
install:
make build
mv ${BINARY_NAME} ${BIN_DIR}
clean:
@if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi
@@ -0,0 +1,16 @@
package internal_service
import (
"Open_IM/src/common/config"
pbUser "Open_IM/src/proto/user"
"context"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"strings"
)
func GetUserInfoClient(req *pbUser.GetUserInfoReq) (*pbUser.GetUserInfoResp, error) {
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
client := pbUser.NewUserClient(etcdConn)
RpcResp, err := client.GetUserInfo(context.Background(), req)
return RpcResp, err
}
+13
View File
@@ -0,0 +1,13 @@
package main
import (
"Open_IM/src/rpc/user/user"
"flag"
)
func main() {
rpcPort := flag.Int("port", 10100, "rpc listening port")
flag.Parse()
rpcServer := user.NewUserServer(*rpcPort)
rpcServer.Run()
}
+96
View File
@@ -0,0 +1,96 @@
package user
import (
"Open_IM/src/common/config"
"Open_IM/src/common/db/mysql_model/im_mysql_model"
"Open_IM/src/common/log"
pbUser "Open_IM/src/proto/user"
"Open_IM/src/utils"
"context"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"google.golang.org/grpc"
"net"
"strconv"
"strings"
)
type userServer struct {
rpcPort int
rpcRegisterName string
etcdSchema string
etcdAddr []string
}
func NewUserServer(port int) *userServer {
return &userServer{
rpcPort: port,
rpcRegisterName: config.Config.RpcRegisterName.OpenImUserName,
etcdSchema: config.Config.Etcd.EtcdSchema,
etcdAddr: config.Config.Etcd.EtcdAddr,
}
}
func (s *userServer) Run() {
log.Info("", "", "rpc user init....")
ip := utils.ServerIP
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
//listener network
listener, err := net.Listen("tcp", registerAddress)
if err != nil {
log.InfoByArgs("listen network failed,err=%s", err.Error())
return
}
log.Info("", "", "listen network success, address = %s", registerAddress)
defer listener.Close()
//grpc server
srv := grpc.NewServer()
defer srv.GracefulStop()
//Service registers with etcd
pbUser.RegisterUserServer(srv, s)
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
if err != nil {
log.ErrorByArgs("register rpc token to etcd failed,err=%s", err.Error())
return
}
err = srv.Serve(listener)
if err != nil {
log.ErrorByArgs("listen token failed,err=%s", err.Error())
return
}
log.Info("", "", "rpc token init success")
}
func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq) (*pbUser.GetUserInfoResp, error) {
log.InfoByKv("rpc get_user_info is server", req.OperationID)
var userInfoList []*pbUser.UserInfo
//Obtain user information according to userID
if len(req.UserIDList) > 0 {
for _, userID := range req.UserIDList {
var userInfo pbUser.UserInfo
user, err := im_mysql_model.FindUserByUID(userID)
if err != nil {
log.ErrorByKv("search userinfo failed", req.OperationID, "userID", userID, "err=%s", err.Error())
continue
}
userInfo.Uid = user.UID
userInfo.Icon = user.Icon
userInfo.Name = user.Name
userInfo.Gender = user.Gender
userInfo.Mobile = user.Mobile
userInfo.Birth = user.Birth
userInfo.Email = user.Email
userInfo.Ex = user.Ex
userInfoList = append(userInfoList, &userInfo)
}
} else {
return &pbUser.GetUserInfoResp{ErrorCode: 999, ErrorMsg: "uidList is nil"}, nil
}
log.InfoByKv("rpc get userInfo return success", req.OperationID, "token", req.Token)
return &pbUser.GetUserInfoResp{
ErrorCode: 0,
ErrorMsg: "",
Data: userInfoList,
}, nil
}
+25
View File
@@ -0,0 +1,25 @@
package user
import (
"Open_IM/src/common/config"
"Open_IM/src/common/db/mysql_model/im_mysql_model"
log2 "Open_IM/src/common/log"
pbUser "Open_IM/src/proto/user"
"Open_IM/src/utils"
"context"
)
func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserInfoReq) (*pbUser.CommonResp, error) {
log2.Info(req.Token, req.OperationID, "rpc modify user is server,args=%s", req.String())
claims, err := utils.ParseToken(req.Token)
if err != nil {
log2.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
return &pbUser.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: err.Error()}, nil
}
err = im_mysql_model.UpDateUserInfo(claims.UID, req.Name, req.Icon, req.Mobile, req.Birth, req.Email, req.Ex, req.Gender)
if err != nil {
log2.Error(req.Token, req.OperationID, "update user some attribute failed,err=%s", err.Error())
return &pbUser.CommonResp{ErrorCode: config.ErrModifyUserInfo.ErrCode, ErrorMsg: config.ErrModifyUserInfo.ErrMsg}, nil
}
return &pbUser.CommonResp{}, nil
}