TODO: GRPC调用
This commit is contained in:
parent
6e8fdc6b7c
commit
bcb97d4455
33
README.md
33
README.md
@ -1,3 +1,36 @@
|
|||||||
# user-core-client
|
# user-core-client
|
||||||
|
|
||||||
用户中心 SDK
|
用户中心 SDK
|
||||||
|
|
||||||
|
**数据同步**
|
||||||
|
|
||||||
|
内部使用Kafka订阅进行同步
|
||||||
|
|
||||||
|
```go
|
||||||
|
type UserCentSync interface {
|
||||||
|
Start(ctx context.Context) error
|
||||||
|
Stop(ctx context.Context) error
|
||||||
|
|
||||||
|
// SetCallUserListener 设置用户事件回调函数
|
||||||
|
SetCallUserListener(func (context.Context, *UserEvent) error)
|
||||||
|
// SetErrorListener 设置错误回调函数
|
||||||
|
SetErrorListener(func (context.Context, error) error)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**API调用**
|
||||||
|
|
||||||
|
内部使用GRPC调用
|
||||||
|
|
||||||
|
```go
|
||||||
|
type UserCenterApi interface {
|
||||||
|
// Verify 验证 token 并且返回 token 中的信息
|
||||||
|
Verify(ctx context.Context, token string) (*TokenClaims, error)
|
||||||
|
|
||||||
|
// GetPhoneTextByUID 获取明文手机号 来自于 uid
|
||||||
|
GetPhoneTextByUID(ctx context.Context, uid int64) (string, error)
|
||||||
|
|
||||||
|
// UpdateUserByUID 更新用户信息
|
||||||
|
UpdateUserByUID(ctx context.Context, uid int64, user *UpdateUserReq) (*User, error)
|
||||||
|
}
|
||||||
|
```
|
@ -1 +1,23 @@
|
|||||||
package user_core_client
|
package user_core_client
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
type UserCenterApi interface {
|
||||||
|
// Verify 验证 token 并且返回 token 中的信息
|
||||||
|
Verify(ctx context.Context, token string) (*TokenClaims, error)
|
||||||
|
|
||||||
|
// GetPhoneTextByUID 获取明文手机号 来自于 uid
|
||||||
|
GetPhoneTextByUID(ctx context.Context, uid int64) (string, error)
|
||||||
|
|
||||||
|
// UpdateUserByUID 更新用户信息
|
||||||
|
UpdateUserByUID(ctx context.Context, uid int64, user *UpdateUserReq) (*User, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateUserReq struct {
|
||||||
|
Username string `json:"username" ` // 名称(可重复)
|
||||||
|
PhoneText string `json:"phoneText"` // 手机号
|
||||||
|
Password string `json:"password"` // 加密密码
|
||||||
|
Gender string `json:"gender"` // 性别 (male 男性, female 女性, unknown 未知)
|
||||||
|
Status string `json:"status"` // 用户状态,enabled/disabled
|
||||||
|
LoginName string `json:"loginName"` // 登录名
|
||||||
|
}
|
||||||
|
58
client_api_grpc.go
Normal file
58
client_api_grpc.go
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package user_core_client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GrpcConfig struct {
|
||||||
|
Target string // grpc 目标地址
|
||||||
|
Timeout time.Duration // 超时时间, 默认为 1秒
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUserCenterApi(platformCode string, grpcConfig *GrpcConfig) (UserCenterApi, func(), error) {
|
||||||
|
grpcConn, err := grpc.NewClient(grpcConfig.Target, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &userCenterApi{
|
||||||
|
platformCode: platformCode,
|
||||||
|
grpcConfig: grpcConfig,
|
||||||
|
grpcConn: grpcConn,
|
||||||
|
},
|
||||||
|
func() { _ = grpcConn.Close() },
|
||||||
|
nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type userCenterApi struct {
|
||||||
|
platformCode string
|
||||||
|
grpcConfig *GrpcConfig
|
||||||
|
grpcConn *grpc.ClientConn
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *userCenterApi) Verify(ctx context.Context, token string) (*TokenClaims, error) {
|
||||||
|
//TODO implement me
|
||||||
|
|
||||||
|
st := status.Convert(nil)
|
||||||
|
st.Code()
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *userCenterApi) GetPhoneTextByToken(ctx context.Context, token string) (string, error) {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *userCenterApi) GetPhoneTextByUID(ctx context.Context, uid int64) (string, error) {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *userCenterApi) UpdateUserByUID(ctx context.Context, uid int64, user *UpdateUserReq) (*User, error) {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
@ -4,10 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EventTyped interface {
|
|
||||||
GetEventType() string
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserCentSync interface {
|
type UserCentSync interface {
|
||||||
Start(ctx context.Context) error
|
Start(ctx context.Context) error
|
||||||
Stop(ctx context.Context) error
|
Stop(ctx context.Context) error
|
||||||
|
5
go.mod
5
go.mod
@ -10,5 +10,10 @@ require (
|
|||||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||||
github.com/xdg-go/scram v1.1.2 // indirect
|
github.com/xdg-go/scram v1.1.2 // indirect
|
||||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
github.com/xdg-go/stringprep v1.0.4 // indirect
|
||||||
|
golang.org/x/net v0.40.0 // indirect
|
||||||
|
golang.org/x/sys v0.33.0 // indirect
|
||||||
golang.org/x/text v0.28.0 // indirect
|
golang.org/x/text v0.28.0 // indirect
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250528174236-200df99c418a // indirect
|
||||||
|
google.golang.org/grpc v1.74.2 // indirect
|
||||||
|
google.golang.org/protobuf v1.36.6 // indirect
|
||||||
)
|
)
|
||||||
|
10
go.sum
10
go.sum
@ -35,6 +35,8 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
|||||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||||
|
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
|
||||||
|
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
@ -46,6 +48,8 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
||||||
|
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
@ -65,6 +69,12 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
|
|||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250528174236-200df99c418a h1:v2PbRU4K3llS09c7zodFpNePeamkAwG3mPrAery9VeE=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250528174236-200df99c418a/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A=
|
||||||
|
google.golang.org/grpc v1.74.2 h1:WoosgB65DlWVC9FqI82dGsZhWFNBSLjQ84bjROOpMu4=
|
||||||
|
google.golang.org/grpc v1.74.2/go.mod h1:CtQ+BGjaAIXHs/5YS3i473GqwBBa1zGQNevxdeBEXrM=
|
||||||
|
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
||||||
|
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
@ -2,6 +2,11 @@ package user_core_client
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
|
type TokenClaims struct {
|
||||||
|
UserID string `json:"userId"`
|
||||||
|
PlatformCode string `json:"platformCode"`
|
||||||
|
}
|
||||||
|
|
||||||
// Event 接口定义了所有事件应具备的基本元数据
|
// Event 接口定义了所有事件应具备的基本元数据
|
||||||
type Event interface {
|
type Event interface {
|
||||||
GetEventID() string // 获取事件唯一ID
|
GetEventID() string // 获取事件唯一ID
|
||||||
@ -17,11 +22,13 @@ type User struct {
|
|||||||
DeletedAt uint `json:"deleted_at"` // 软删除时间 毫秒 0 表示未删除
|
DeletedAt uint `json:"deleted_at"` // 软删除时间 毫秒 0 表示未删除
|
||||||
|
|
||||||
EncryptedPhone string `json:"encrypted_phone" ` // 加密后的手机号
|
EncryptedPhone string `json:"encrypted_phone" ` // 加密后的手机号
|
||||||
Username string `json:"username" ` // 用户名(可重复)
|
|
||||||
LoginName string `json:"login_name" ` // 登录名
|
|
||||||
Gender string `json:"gender" ` // 性别 (male 男性, female 女性, unknown 未知)
|
|
||||||
PhoneMask string `json:"phone_mask" ` // 手机号掩码(前三后四位)
|
PhoneMask string `json:"phone_mask" ` // 手机号掩码(前三后四位)
|
||||||
Status string `json:"status" ` // 用户状态,enabled/disabled
|
|
||||||
|
Username string `json:"username" ` // 用户名(可重复)
|
||||||
|
LoginName string `json:"login_name" ` // 登录名
|
||||||
|
|
||||||
|
Gender string `json:"gender" ` // 性别 (male 男性, female 女性, unknown 未知)
|
||||||
|
Status string `json:"status" ` // 用户状态,enabled/disabled
|
||||||
}
|
}
|
||||||
|
|
||||||
type BaseEvent struct {
|
type BaseEvent struct {
|
Loading…
Reference in New Issue
Block a user