rpc
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.1 KiB

package user
import (
"github.com/golang/protobuf/proto"
)
func GetUserByToken(dbname, token string, url ...string) (map[string]string, 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 map[string]string{}, err
}
defer conn.Close()
req := &UserRequest{proto.String(dbname), proto.String(token), nil}
res := &UserResponse{}
err = conn.GetByToken(req, res)
if err != nil {
return map[string]string{}, err
}
if res.GetUserId() != "" {
return map[string]string{
"UserId": res.GetUserId(),
"Username": res.GetUsername(),
"Nickname": res.GetNickname(),
"Mobile": res.GetMobile(),
"Email": res.GetEmail(),
"Status": res.GetStatus(),
"BusinessId": res.GetBusinessId(),
"StoreId": res.GetStoreId(),
"FansTo": res.GetFansTo(),
"IsVip": res.GetIsVip(),
"Usercode": res.GetUsercode(),
"GroupId": res.GetGroupId(),
}, nil
}
return map[string]string{}, nil
}
func Login(dbname, account, password string, url ...string) (map[string]string, 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 map[string]string{}, err
}
defer conn.Close()
req := &LoginRequest{proto.String(dbname), proto.String(account), proto.String(password), nil}
res := &LoginResponse{}
err = conn.Login(req, res)
if err != nil {
return map[string]string{}, err
}
if res.GetUserId() != "" {
return map[string]string{
"UserId": res.GetUserId(),
"Username": res.GetUsername(),
"Nickname": res.GetNickname(),
"Mobile": res.GetMobile(),
"Email": res.GetEmail(),
"Status": res.GetStatus(),
"BusinessId": res.GetBusinessId(),
"StoreId": res.GetStoreId(),
"FansTo": res.GetFansTo(),
"IsVip": res.GetIsVip(),
"Token": res.GetToken(),
"Usercode": res.GetUsercode(),
"GroupId": res.GetGroupId(),
}, nil
}
return map[string]string{}, nil
}