作者 yangfu

服务分层

@@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
8 "encoding/hex" 8 "encoding/hex"
9 9
10 "gitlab.fjmaimaimai.com/mmm-go/ability/protocol" 10 "gitlab.fjmaimaimai.com/mmm-go/ability/protocol"
11 - "gitlab.fjmaimaimai.com/mmm-go/ability/services/auth" 11 + s_auth "gitlab.fjmaimaimai.com/mmm-go/ability/services/auth"
12 "gitlab.fjmaimaimai.com/mmm-go/gocomm/common" 12 "gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
13 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 13 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
14 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" 14 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
@@ -18,6 +18,10 @@ import ( @@ -18,6 +18,10 @@ import (
18 "github.com/astaxie/beego/validation" 18 "github.com/astaxie/beego/validation"
19 ) 19 )
20 20
  21 +var(
  22 + auth s_auth.IAuthService = &s_auth.AuthService{}
  23 +)
  24 +
21 type BaseController struct { 25 type BaseController struct {
22 mybeego.BaseController 26 mybeego.BaseController
23 } 27 }
@@ -4,11 +4,15 @@ import ( @@ -4,11 +4,15 @@ import (
4 "encoding/json" 4 "encoding/json"
5 "gitlab.fjmaimaimai.com/mmm-go/ability/controllers" 5 "gitlab.fjmaimaimai.com/mmm-go/ability/controllers"
6 "gitlab.fjmaimaimai.com/mmm-go/ability/protocol" 6 "gitlab.fjmaimaimai.com/mmm-go/ability/protocol"
7 - "gitlab.fjmaimaimai.com/mmm-go/ability/services/auth" 7 + s_auth "gitlab.fjmaimaimai.com/mmm-go/ability/services/auth"
8 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 8 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
9 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" 9 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
10 ) 10 )
11 11
  12 +var(
  13 + auth s_auth.IAuthService = &s_auth.AuthService{}
  14 +)
  15 +
12 type AuthController struct { 16 type AuthController struct {
13 controllers.BaseController 17 controllers.BaseController
14 } 18 }
  1 +package repository
  2 +
  3 +import "gitlab.fjmaimaimai.com/mmm-go/ability/models"
  4 +
  5 +type IUserRepository interface {
  6 + GetUsersByMobile(mobile string)(v *models.Users, err error)
  7 + GetUserInfoByMobile(mobile string)(v *models.UserInfo, err error)
  8 +}
  9 +
  10 +func assertImplement(){
  11 + var _ IUserRepository = (*UserRepository)(nil)
  12 +}
  13 +
  14 +type UserRepository struct {}
  15 +
  16 +func (r *UserRepository)GetUsersByMobile(mobile string)(v *models.Users, err error) {
  17 + return models.GetUsersByMobile(mobile)
  18 +}
  19 +
  20 +func (r *UserRepository)GetUserInfoByMobile(mobile string)(v *models.UserInfo, err error) {
  21 + return models.GetUserInfoByMobile(mobile)
  22 +}
@@ -2,19 +2,45 @@ package auth @@ -2,19 +2,45 @@ package auth
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "gitlab.fjmaimaimai.com/mmm-go/ability/internal/repository"
5 "gitlab.fjmaimaimai.com/mmm-go/ability/models" 6 "gitlab.fjmaimaimai.com/mmm-go/ability/models"
6 "gitlab.fjmaimaimai.com/mmm-go/ability/protocol" 7 "gitlab.fjmaimaimai.com/mmm-go/ability/protocol"
7 "gitlab.fjmaimaimai.com/mmm-go/gocomm/common" 8 "gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
8 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 9 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
9 "strings" 10 "strings"
10 ) 11 )
  12 +
  13 +type IAuthService interface {
  14 + Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error)
  15 + AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessTokenResponse,err error)
  16 + RefreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.RefreshTokenResponse,err error)
  17 + UpdateDevice(request *protocol.UpdateDeviceRequest)(rsp *protocol.UpdateDeviceResponse,err error)
  18 + CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenResponse,err error)
  19 + CheckUuid(request *protocol.CheckUuidRequest)(rsp *protocol.CheckUuidResponse,err error)
  20 + SmsCode(request *protocol.SmsCodeRequest)(rsp *protocol.SmsCodeResponse,err error)
  21 +}
  22 +
  23 +type AuthService struct {}
  24 +
  25 +func assertImplement(){
  26 + var _ IAuthService = (*AuthService)(nil)
  27 +}
  28 +
  29 +var(
  30 + //服务
  31 + //sms s_sms.ISmsService = &s_sms.SmsService{}
  32 +
  33 + //仓储
  34 + UserRepository repository.IUserRepository =&repository.UserRepository{}
  35 +)
  36 +
11 //登录 37 //登录
12 -func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error){ 38 +func (s *AuthService)Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error){
13 var ( 39 var (
14 user *models.Users 40 user *models.Users
15 userInfo *models.UserInfo 41 userInfo *models.UserInfo
16 ) 42 )
17 - user,err =models.GetUsersByMobile(request.Phone) 43 + user,err =UserRepository.GetUsersByMobile(request.Phone)
18 if err!=nil{ 44 if err!=nil{
19 log.Error(err) 45 log.Error(err)
20 err =common.NewError(2020,err)//账号不存在 46 err =common.NewError(2020,err)//账号不存在
@@ -37,7 +63,7 @@ func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error @@ -37,7 +63,7 @@ func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error
37 } 63 }
38 Success: 64 Success:
39 { 65 {
40 - userInfo,err =models.GetUserInfoByMobile(request.Phone) 66 + userInfo,err =UserRepository.GetUserInfoByMobile(request.Phone)
41 if err!=nil{ 67 if err!=nil{
42 log.Error(err) 68 log.Error(err)
43 return 69 return
@@ -47,17 +73,12 @@ func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error @@ -47,17 +73,12 @@ func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error
47 } 73 }
48 return 74 return
49 } 75 }
50 -//短信验证码  
51 -func SmsCode(request *protocol.SmsCodeRequest)(rsp *protocol.SmsCodeResponse,err error){  
52 - return nil,nil  
53 -}  
54 //更新设备信息 76 //更新设备信息
55 -func UpdateDevice(request *protocol.UpdateDeviceRequest)(rsp *protocol.UpdateDeviceResponse,err error){ 77 +func (s *AuthService)UpdateDevice(request *protocol.UpdateDeviceRequest)(rsp *protocol.UpdateDeviceResponse,err error){
56 return nil,nil 78 return nil,nil
57 } 79 }
58 -  
59 //获取accessToken 80 //获取accessToken
60 -func AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessTokenResponse,err error){ 81 +func (s *AuthService)AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessTokenResponse,err error){
61 var ( 82 var (
62 userInfo *models.UserInfo 83 userInfo *models.UserInfo
63 ) 84 )
@@ -78,7 +99,7 @@ func AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessToken @@ -78,7 +99,7 @@ func AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessToken
78 return 99 return
79 } 100 }
80 //刷新token 101 //刷新token
81 -func RefreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.RefreshTokenResponse,err error){ 102 +func (s *AuthService)RefreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.RefreshTokenResponse,err error){
82 var ( 103 var (
83 userInfo *models.UserInfo 104 userInfo *models.UserInfo
84 newAccess *protocol.Access 105 newAccess *protocol.Access
@@ -110,7 +131,7 @@ func refreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.Access,er @@ -110,7 +131,7 @@ func refreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.Access,er
110 return nil,nil 131 return nil,nil
111 } 132 }
112 //检查token有效性 133 //检查token有效性
113 -func CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenResponse,err error){ 134 +func (s *AuthService)CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenResponse,err error){
114 var ( 135 var (
115 userInfo *models.UserInfo 136 userInfo *models.UserInfo
116 ) 137 )
@@ -130,7 +151,7 @@ func CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenRes @@ -130,7 +151,7 @@ func CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenRes
130 return 151 return
131 } 152 }
132 //检查uuid 是否重复 153 //检查uuid 是否重复
133 -func CheckUuid(request *protocol.CheckUuidRequest)(rsp *protocol.CheckUuidResponse,err error){ 154 +func (s *AuthService)CheckUuid(request *protocol.CheckUuidRequest)(rsp *protocol.CheckUuidResponse,err error){
134 var ( 155 var (
135 logUuid *models.LogUuid 156 logUuid *models.LogUuid
136 ) 157 )
@@ -144,4 +165,8 @@ func CheckUuid(request *protocol.CheckUuidRequest)(rsp *protocol.CheckUuidRespon @@ -144,4 +165,8 @@ func CheckUuid(request *protocol.CheckUuidRequest)(rsp *protocol.CheckUuidRespon
144 models.AddLogUuid(&models.LogUuid{Uuid:request.Uuid}) 165 models.AddLogUuid(&models.LogUuid{Uuid:request.Uuid})
145 rsp =&protocol.CheckUuidResponse{} 166 rsp =&protocol.CheckUuidResponse{}
146 return 167 return
  168 +}
  169 +//短信验证码
  170 +func (s *AuthService)SmsCode(request *protocol.SmsCodeRequest)(rsp *protocol.SmsCodeResponse,err error){
  171 + return nil,nil
147 } 172 }
  1 +package sms
  2 +
  3 +type ISmsService interface {
  4 +
  5 +}
  6 +
  7 +type SmsService struct {}
  8 +
  9 +func assertImplement(){
  10 + var _ ISmsService = (*SmsService)(nil)
  11 +}
  12 +//发送