From 738d76190a0b04387a527b8c12cf6cc4d45f8b99 Mon Sep 17 00:00:00 2001 From: guzeng Date: Tue, 9 Mar 2021 15:20:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7=E5=90=8D?= =?UTF-8?q?=E5=8F=8A=E7=BC=96=E5=8F=B7=E7=9A=84RPC=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user/user.client.go | 58 +++++++++++++++++++++++++++++++++++++++++++++ user/user.pb.go | 52 ++++++++++++++++++++++++++++++++++++++++ user/user.proto | 10 ++++++++ 3 files changed, 120 insertions(+) diff --git a/user/user.client.go b/user/user.client.go index 9a3cd19..d65574d 100644 --- a/user/user.client.go +++ b/user/user.client.go @@ -47,6 +47,64 @@ func GetUserByToken(dbname, token string, url ...string) (map[string]string, err return map[string]string{}, nil } +/** + * 使用用户名查询 + */ +func GetUserByUsername(dbname, username string, url ...string) (*UserResponse, error) { + + var user_rpc_url string = "127.0.0.1:7976" + if len(url) > 0 && url[0] != "" { + user_rpc_url = url[0] + } + + conn, _, err := DialUserService("tcp", user_rpc_url) + if err != nil { + return nil, err + } + defer conn.Close() + + req := &UserInfoByUsername{proto.String(dbname), proto.String(username), nil} + + res := &UserResponse{} + + err = conn.GetByUsername(req, res) + + if err != nil { + return nil, err + } + + return res, nil +} + +/** + * 使用编号查询 + */ +func GetUserByUsercode(dbname, usercode string, url ...string) (*UserResponse, error) { + + var user_rpc_url string = "127.0.0.1:7976" + if len(url) > 0 && url[0] != "" { + user_rpc_url = url[0] + } + + conn, _, err := DialUserService("tcp", user_rpc_url) + if err != nil { + return nil, err + } + defer conn.Close() + + req := &UserInfoByUsercode{proto.String(dbname), proto.String(usercode), nil} + + res := &UserResponse{} + + err = conn.GetByUsercode(req, res) + + if err != nil { + return nil, err + } + + return res, nil +} + func Login(dbname, account, password string, url ...string) (map[string]string, error) { var user_rpc_url string = "127.0.0.1:7976" diff --git a/user/user.pb.go b/user/user.pb.go index 25723ed..3dd7cff 100644 --- a/user/user.pb.go +++ b/user/user.pb.go @@ -10,6 +10,8 @@ It is generated from these files: It has these top-level messages: UserRequest + UserInfoByUsername + UserInfoByUsercode UserResponse LoginRequest LoginResponse @@ -55,6 +57,56 @@ func (m *UserRequest) GetToken() string { return "" } +// 使用username查询用户信息请求结构 +type UserInfoByUsername struct { + Dbname *string `protobuf:"bytes,1,opt,name=dbname" json:"dbname,omitempty"` + Username *string `protobuf:"bytes,2,opt,name=username" json:"username,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *UserInfoByUsername) Reset() { *m = UserInfoByUsername{} } +func (m *UserInfoByUsername) String() string { return proto.CompactTextString(m) } +func (*UserInfoByUsername) ProtoMessage() {} + +func (m *UserInfoByUsername) GetDbname() string { + if m != nil && m.Dbname != nil { + return *m.Dbname + } + return "" +} + +func (m *UserInfoByUsername) GetUsername() string { + if m != nil && m.Username != nil { + return *m.Username + } + return "" +} + +// 使用usercode查询用户信息请求结构 +type UserInfoByUsercode struct { + Dbname *string `protobuf:"bytes,1,opt,name=dbname" json:"dbname,omitempty"` + Usercode *string `protobuf:"bytes,2,opt,name=usercode" json:"usercode,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *UserInfoByUsercode) Reset() { *m = UserInfoByUsercode{} } +func (m *UserInfoByUsercode) String() string { return proto.CompactTextString(m) } +func (*UserInfoByUsercode) ProtoMessage() {} + +func (m *UserInfoByUsercode) GetDbname() string { + if m != nil && m.Dbname != nil { + return *m.Dbname + } + return "" +} + +func (m *UserInfoByUsercode) GetUsercode() string { + if m != nil && m.Usercode != nil { + return *m.Usercode + } + return "" +} + // 使用token查询用户信息响应结构 type UserResponse struct { UserId *string `protobuf:"bytes,1,opt,name=user_id" json:"user_id,omitempty"` diff --git a/user/user.proto b/user/user.proto index 79bc70a..f4ecc45 100644 --- a/user/user.proto +++ b/user/user.proto @@ -6,7 +6,17 @@ message UserRequest { string dbname = 1; string token = 2; } +// 使用username查询用户信息请求结构 +message UserInfoByUsername { + string dbname = 1; + string username = 2; +} +// 使用usercode查询用户信息请求结构 +message UserInfoByUsercode { + string dbname = 1; + string usercode = 2; +} // 使用token查询用户信息响应结构 message UserResponse { string user_id = 1; //ID