Browse Source

增加用户名及编号的RPC请求方式

master v0.2.0
guzeng 3 years ago
parent
commit
738d76190a
3 changed files with 120 additions and 0 deletions
  1. +58
    -0
      user/user.client.go
  2. +52
    -0
      user/user.pb.go
  3. +10
    -0
      user/user.proto

+ 58
- 0
user/user.client.go View File

@ -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"


+ 52
- 0
user/user.pb.go View File

@ -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"`


+ 10
- 0
user/user.proto View File

@ -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


Loading…
Cancel
Save