sso_rpc.go 914 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package sso
  2. import (
  3. "context"
  4. "eta/eta_mini_crm_ht/rpc"
  5. "eta/eta_mini_crm_ht/utils"
  6. "fmt"
  7. "sync"
  8. )
  9. var (
  10. once sync.Once
  11. rpcPool utils.ClientPool
  12. SSOServiceImpl *SSOService
  13. )
  14. type SSOService struct {
  15. ssoRPCService
  16. }
  17. type ssoRPCService struct {
  18. rpc.DefaultRpcClient
  19. }
  20. func GetSSOService() *SSOService {
  21. once.Do(func() {
  22. c := ssoRPCService{}
  23. rpcPool = c.GetPool(utils.SSO_URL)
  24. SSOServiceImpl = &SSOService{c}
  25. })
  26. return SSOServiceImpl
  27. }
  28. func (s *SSOService) SSOLogin(request *LoginRequest) {
  29. conn := rpcPool.Get()
  30. defer rpcPool.Put(conn)
  31. ssoLoginService := NewSSOLoginClient(conn)
  32. s.WrapSign(request, func(ctx context.Context, request interface{}) (err error) {
  33. loginReq := request.(*LoginRequest)
  34. rep, err := ssoLoginService.Login(ctx, loginReq)
  35. if err != nil {
  36. fmt.Printf("rpc error: %v", err)
  37. } else {
  38. fmt.Printf("rpc result: %v", rep)
  39. }
  40. return
  41. })
  42. }