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

3 years ago
  1. package user
  2. import (
  3. "github.com/golang/protobuf/proto"
  4. )
  5. func GetUserByToken(dbname, token string, url ...string) (map[string]string, error) {
  6. var user_rpc_url string = "127.0.0.1:7976"
  7. if len(url) > 0 && url[0] != "" {
  8. user_rpc_url = url[0]
  9. }
  10. conn, _, err := DialUserService("tcp", user_rpc_url)
  11. if err != nil {
  12. return map[string]string{}, err
  13. }
  14. defer conn.Close()
  15. req := &UserRequest{proto.String(dbname), proto.String(token), nil}
  16. res := &UserResponse{}
  17. err = conn.GetByToken(req, res)
  18. if err != nil {
  19. return map[string]string{}, err
  20. }
  21. if res.GetUserId() != "" {
  22. return map[string]string{
  23. "UserId": res.GetUserId(),
  24. "Username": res.GetUsername(),
  25. "Nickname": res.GetNickname(),
  26. "Mobile": res.GetMobile(),
  27. "Email": res.GetEmail(),
  28. "Status": res.GetStatus(),
  29. "BusinessId": res.GetBusinessId(),
  30. "StoreId": res.GetStoreId(),
  31. "FansTo": res.GetFansTo(),
  32. "IsVip": res.GetIsVip(),
  33. "Usercode": res.GetUsercode(),
  34. "GroupId": res.GetGroupId(),
  35. }, nil
  36. }
  37. return map[string]string{}, nil
  38. }
  39. func Login(dbname, account, password string, url ...string) (map[string]string, error) {
  40. var user_rpc_url string = "127.0.0.1:7976"
  41. if len(url) > 0 && url[0] != "" {
  42. user_rpc_url = url[0]
  43. }
  44. conn, _, err := DialUserService("tcp", user_rpc_url)
  45. if err != nil {
  46. return map[string]string{}, err
  47. }
  48. defer conn.Close()
  49. req := &LoginRequest{proto.String(dbname), proto.String(account), proto.String(password), nil}
  50. res := &LoginResponse{}
  51. err = conn.Login(req, res)
  52. if err != nil {
  53. return map[string]string{}, err
  54. }
  55. if res.GetUserId() != "" {
  56. return map[string]string{
  57. "UserId": res.GetUserId(),
  58. "Username": res.GetUsername(),
  59. "Nickname": res.GetNickname(),
  60. "Mobile": res.GetMobile(),
  61. "Email": res.GetEmail(),
  62. "Status": res.GetStatus(),
  63. "BusinessId": res.GetBusinessId(),
  64. "StoreId": res.GetStoreId(),
  65. "FansTo": res.GetFansTo(),
  66. "IsVip": res.GetIsVip(),
  67. "Token": res.GetToken(),
  68. "Usercode": res.GetUsercode(),
  69. "GroupId": res.GetGroupId(),
  70. }, nil
  71. }
  72. return map[string]string{}, nil
  73. }