feat: user items
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
FROM golang:1.26.5-alpine AS builder
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
ENV GOPROXY=https://goproxy.cn,direct \
|
||||
CGO_ENABLED=0 \
|
||||
GOOS=linux \
|
||||
GOARCH=amd64
|
||||
|
||||
COPY pkg ./pkg
|
||||
COPY user/go.mod user/go.sum ./user/
|
||||
|
||||
WORKDIR /src/user
|
||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||
go mod download
|
||||
|
||||
COPY user/ ./
|
||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
go build -ldflags="-s -w" -o /out/user .
|
||||
|
||||
FROM alpine:3.22
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
RUN apk add --no-cache tzdata \
|
||||
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
|
||||
&& echo "Asia/Shanghai" > /etc/timezone
|
||||
|
||||
COPY --from=builder /out/user .
|
||||
|
||||
EXPOSE 10300
|
||||
|
||||
CMD ["./user", "-f", "etc/user.yaml"]
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
Nacos:
|
||||
Hosts:
|
||||
- nacos:8848
|
||||
- rnacos:8848
|
||||
NamespaceId: test
|
||||
Group: LONE_SERVICES
|
||||
RegisterIP: user
|
||||
|
||||
@@ -79,3 +79,34 @@ type UserLoginSession struct {
|
||||
AppId uint32 `json:"app_id"`
|
||||
LastTime utils.CustomTime `json:"last_time"`
|
||||
}
|
||||
|
||||
type UserListRow struct {
|
||||
Id int64 `gorm:"column:id" json:"id"`
|
||||
Username string `gorm:"column:username" json:"username"`
|
||||
Nickname string `gorm:"column:nickname" json:"nickname"`
|
||||
Avatar string `gorm:"column:avatar" json:"avatar"`
|
||||
Mobile string `gorm:"column:mobile" json:"mobile"`
|
||||
OnTrialNum int `gorm:"column:on_trial_num" json:"on_trial_num"`
|
||||
Gender int `gorm:"column:gender" json:"gender"`
|
||||
Birthday string `gorm:"column:birthday" json:"birthday"`
|
||||
CreatedAt utils.CustomTime `gorm:"column:created_at" json:"created_at"`
|
||||
UpdatedAt utils.CustomTime `gorm:"column:updated_at" json:"updated_at"`
|
||||
}
|
||||
|
||||
type UserListItem struct {
|
||||
Id int64 `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Nickname string `json:"nickname"`
|
||||
HeadPortrait string `json:"head_portrait"`
|
||||
Mobile string `json:"mobile"`
|
||||
OnTrialNum int `json:"on_trial_num"`
|
||||
Gender int `json:"gender"`
|
||||
Birthday string `json:"birthday"`
|
||||
CreatedAt utils.CustomTime `json:"created_at"`
|
||||
UpdatedAt utils.CustomTime `json:"updated_at"`
|
||||
}
|
||||
|
||||
type UserItemsData struct {
|
||||
Count int64 `json:"count"`
|
||||
Items []UserListItem `json:"items"`
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"user/internal/dao"
|
||||
"user/internal/model"
|
||||
"user/internal/svc"
|
||||
"user/user"
|
||||
"user/validator"
|
||||
|
||||
"pkg.local/log"
|
||||
"pkg.local/modelbase"
|
||||
"pkg.local/utils"
|
||||
validateService "pkg.local/validate"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UserItemsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUserItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserItemsLogic {
|
||||
return &UserItemsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserItemsLogic) UserItems(in *user.UserItemsReq) (*user.Response, error) {
|
||||
var v validator.UserItemsValidator
|
||||
if msg := validateService.ValidateFromProto(in, &v); msg != utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return failResponse(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
|
||||
page := int(v.Page)
|
||||
size := int(v.Size)
|
||||
if page < modelbase.DefaultPage {
|
||||
page = modelbase.DefaultPage
|
||||
}
|
||||
if size < utils.NumberOne {
|
||||
size = modelbase.DefaultSize
|
||||
}
|
||||
|
||||
where := map[string]string{}
|
||||
if v.Mobile != utils.StringEmpty {
|
||||
mobile, cErr := utils.Crypto{}.AESEncryptECB(v.Mobile)
|
||||
if cErr != nil {
|
||||
log.Errorf("user items encrypt mobile: %v", cErr)
|
||||
return failResponse(utils.ErrorEncryptAesError), nil
|
||||
}
|
||||
where["mobile"] = mobile
|
||||
}
|
||||
|
||||
var list []dao.UserListRow
|
||||
result, err := model.UserModel{}.Init().Page(modelbase.Params{
|
||||
Eq: where,
|
||||
Order: "id DESC",
|
||||
Page: page,
|
||||
Size: size,
|
||||
}, &list)
|
||||
if err != nil {
|
||||
log.Errorf("user items: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
items := make([]dao.UserListItem, 0, len(list))
|
||||
for _, row := range list {
|
||||
headPortrait, _ := utils.BuildImageURL(row.Avatar).(string)
|
||||
items = append(items, dao.UserListItem{
|
||||
Id: row.Id,
|
||||
Username: row.Username,
|
||||
Nickname: row.Nickname,
|
||||
HeadPortrait: headPortrait,
|
||||
Mobile: utils.DecryptMobile(row.Mobile),
|
||||
OnTrialNum: row.OnTrialNum,
|
||||
Gender: row.Gender,
|
||||
Birthday: row.Birthday,
|
||||
CreatedAt: row.CreatedAt,
|
||||
UpdatedAt: row.UpdatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
return okResponse(dao.UserItemsData{
|
||||
Count: result.Count,
|
||||
Items: items,
|
||||
}), nil
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"user/internal/model"
|
||||
"user/internal/svc"
|
||||
"user/user"
|
||||
"user/validator"
|
||||
|
||||
"pkg.local/log"
|
||||
"pkg.local/modelbase"
|
||||
"pkg.local/utils"
|
||||
validateService "pkg.local/validate"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UserStatusLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUserStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserStatusLogic {
|
||||
return &UserStatusLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserStatusLogic) UserStatus(in *user.UserStatusReq) (*user.Response, error) {
|
||||
var v validator.UserStatusValidator
|
||||
if msg := validateService.ValidateFromProto(in, &v); msg != utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return failResponse(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
|
||||
_, err := model.UserModel{}.Init().Edit(modelbase.Params{
|
||||
Eq: map[string]string{
|
||||
"id": strconv.FormatInt(v.Id, utils.NumberTen),
|
||||
},
|
||||
}, map[string]interface{}{
|
||||
"status": v.Status,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("user status: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
return okResponse(nil), nil
|
||||
}
|
||||
@@ -37,3 +37,13 @@ func (s *UserServer) Login(ctx context.Context, in *user.LoginReq) (*user.Respon
|
||||
l := logic.NewLoginLogic(ctx, s.svcCtx)
|
||||
return l.Login(in)
|
||||
}
|
||||
|
||||
func (s *UserServer) UserItems(ctx context.Context, in *user.UserItemsReq) (*user.Response, error) {
|
||||
l := logic.NewUserItemsLogic(ctx, s.svcCtx)
|
||||
return l.UserItems(in)
|
||||
}
|
||||
|
||||
func (s *UserServer) UserStatus(ctx context.Context, in *user.UserStatusReq) (*user.Response, error) {
|
||||
l := logic.NewUserStatusLogic(ctx, s.svcCtx)
|
||||
return l.UserStatus(in)
|
||||
}
|
||||
|
||||
@@ -37,6 +37,19 @@ message LoginReq {
|
||||
string openid = 1;
|
||||
}
|
||||
|
||||
// 管理端用户列表
|
||||
message UserItemsReq {
|
||||
string mobile = 1;
|
||||
int32 page = 2;
|
||||
int32 size = 3;
|
||||
}
|
||||
|
||||
// 管理端修改用户状态
|
||||
message UserStatusReq {
|
||||
int64 id = 1;
|
||||
int32 status = 2;
|
||||
}
|
||||
|
||||
service User {
|
||||
rpc Register(RegisterReq) returns (Response) {
|
||||
option (google.api.http) = {
|
||||
@@ -56,4 +69,16 @@ service User {
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
rpc UserItems(UserItemsReq) returns (Response) {
|
||||
option (google.api.http) = {
|
||||
get: "/admin/v3/user/items"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
rpc UserStatus(UserStatusReq) returns (Response) {
|
||||
option (google.api.http) = {
|
||||
put: "/admin/v3/user/status"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
[base]
|
||||
login_out_time=43200
|
||||
login_refresh_out_time=83200
|
||||
name = "user-service"
|
||||
listenOn = "0.0.0.0:10300"
|
||||
mode = "dev"
|
||||
[log]
|
||||
path = "logs"
|
||||
serviceName = "user-service"
|
||||
mode = "file"
|
||||
encoding = "plain"
|
||||
level = "info"
|
||||
keepDays = 7
|
||||
maxSize = 50
|
||||
maxBackups = 5
|
||||
compress = false
|
||||
# 测试的地址
|
||||
[mysql]
|
||||
host = '39.106.171.204'
|
||||
port = 33066
|
||||
user = 'root'
|
||||
password = 'MOLXRZNOU4Y4'
|
||||
database = 'dms-users'
|
||||
charset = 'utf8mb4'
|
||||
prefix = ''
|
||||
debug = true
|
||||
[mysql_read]
|
||||
host = '39.106.171.204'
|
||||
port = 33066
|
||||
user = 'root'
|
||||
password = 'MOLXRZNOU4Y4'
|
||||
database = 'dms-users'
|
||||
charset = 'utf8mb4'
|
||||
prefix = ''
|
||||
|
||||
[redis]
|
||||
host = '39.106.171.204'
|
||||
password = 'lLMLcuPpzSj'
|
||||
port = 6379
|
||||
db = 0
|
||||
|
||||
[encrypt]
|
||||
data_key = "u2t9T3luZtoRfhBstkFN6TiIMW38BA8a" #内容数据,
|
||||
+146
-16
@@ -82,17 +82,17 @@ func (x *Response) GetData() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 小程序注册(openid),对齐 sales-service user/small/v1/add
|
||||
// 小程序注册
|
||||
type RegisterReq struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Openid string `protobuf:"bytes,1,opt,name=openid,proto3" json:"openid,omitempty"` // 可空;空则服务端模拟 openid(暂不对接微信)
|
||||
Openid string `protobuf:"bytes,1,opt,name=openid,proto3" json:"openid,omitempty"` // 可空;空则服务端模拟
|
||||
Nickname string `protobuf:"bytes,2,opt,name=nickname,proto3" json:"nickname,omitempty"`
|
||||
Avatar string `protobuf:"bytes,3,opt,name=avatar,proto3" json:"avatar,omitempty"`
|
||||
Mobile string `protobuf:"bytes,4,opt,name=mobile,proto3" json:"mobile,omitempty"`
|
||||
Gender uint32 `protobuf:"varint,5,opt,name=gender,proto3" json:"gender,omitempty"` // 1男 2女
|
||||
Birthday string `protobuf:"bytes,6,opt,name=birthday,proto3" json:"birthday,omitempty"`
|
||||
Username string `protobuf:"bytes,7,opt,name=username,proto3" json:"username,omitempty"`
|
||||
AppId uint32 `protobuf:"varint,8,opt,name=app_id,json=appId,proto3" json:"app_id,omitempty"` // 应用标识(数字)
|
||||
AppId uint32 `protobuf:"varint,8,opt,name=app_id,json=appId,proto3" json:"app_id,omitempty"` // 应用标识
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
@@ -183,14 +183,14 @@ func (x *RegisterReq) GetAppId() uint32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// 账号密码注册,对齐 go-sale-admin-api RegisterByUser
|
||||
// 账号密码注册
|
||||
type RegisterByUserReq struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Type uint32 `protobuf:"varint,1,opt,name=type,proto3" json:"type,omitempty"` // 1手机号 2邮箱
|
||||
Account string `protobuf:"bytes,2,opt,name=account,proto3" json:"account,omitempty"`
|
||||
Pwd string `protobuf:"bytes,3,opt,name=pwd,proto3" json:"pwd,omitempty"`
|
||||
Code string `protobuf:"bytes,4,opt,name=code,proto3" json:"code,omitempty"` // 验证码
|
||||
AppId uint32 `protobuf:"varint,5,opt,name=app_id,json=appId,proto3" json:"app_id,omitempty"` // 应用标识(数字)
|
||||
Code string `protobuf:"bytes,4,opt,name=code,proto3" json:"code,omitempty"`
|
||||
AppId uint32 `protobuf:"varint,5,opt,name=app_id,json=appId,proto3" json:"app_id,omitempty"` // 应用标识
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
@@ -260,7 +260,7 @@ func (x *RegisterByUserReq) GetAppId() uint32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// openid 登录,对齐 LoginByOpenid
|
||||
// openid 登录
|
||||
type LoginReq struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Openid string `protobuf:"bytes,1,opt,name=openid,proto3" json:"openid,omitempty"`
|
||||
@@ -305,6 +305,120 @@ func (x *LoginReq) GetOpenid() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 管理端用户列表
|
||||
type UserItemsReq struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Mobile string `protobuf:"bytes,1,opt,name=mobile,proto3" json:"mobile,omitempty"`
|
||||
Page int32 `protobuf:"varint,2,opt,name=page,proto3" json:"page,omitempty"`
|
||||
Size int32 `protobuf:"varint,3,opt,name=size,proto3" json:"size,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *UserItemsReq) Reset() {
|
||||
*x = UserItemsReq{}
|
||||
mi := &file_proto_user_proto_msgTypes[4]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *UserItemsReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*UserItemsReq) ProtoMessage() {}
|
||||
|
||||
func (x *UserItemsReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_user_proto_msgTypes[4]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use UserItemsReq.ProtoReflect.Descriptor instead.
|
||||
func (*UserItemsReq) Descriptor() ([]byte, []int) {
|
||||
return file_proto_user_proto_rawDescGZIP(), []int{4}
|
||||
}
|
||||
|
||||
func (x *UserItemsReq) GetMobile() string {
|
||||
if x != nil {
|
||||
return x.Mobile
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *UserItemsReq) GetPage() int32 {
|
||||
if x != nil {
|
||||
return x.Page
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *UserItemsReq) GetSize() int32 {
|
||||
if x != nil {
|
||||
return x.Size
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// 管理端修改用户状态
|
||||
type UserStatusReq struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
Status int32 `protobuf:"varint,2,opt,name=status,proto3" json:"status,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *UserStatusReq) Reset() {
|
||||
*x = UserStatusReq{}
|
||||
mi := &file_proto_user_proto_msgTypes[5]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *UserStatusReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*UserStatusReq) ProtoMessage() {}
|
||||
|
||||
func (x *UserStatusReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_user_proto_msgTypes[5]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use UserStatusReq.ProtoReflect.Descriptor instead.
|
||||
func (*UserStatusReq) Descriptor() ([]byte, []int) {
|
||||
return file_proto_user_proto_rawDescGZIP(), []int{5}
|
||||
}
|
||||
|
||||
func (x *UserStatusReq) GetId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *UserStatusReq) GetStatus() int32 {
|
||||
if x != nil {
|
||||
return x.Status
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
var File_proto_user_proto protoreflect.FileDescriptor
|
||||
|
||||
const file_proto_user_proto_rawDesc = "" +
|
||||
@@ -330,11 +444,21 @@ const file_proto_user_proto_rawDesc = "" +
|
||||
"\x04code\x18\x04 \x01(\tR\x04code\x12\x15\n" +
|
||||
"\x06app_id\x18\x05 \x01(\rR\x05appId\"\"\n" +
|
||||
"\bLoginReq\x12\x16\n" +
|
||||
"\x06openid\x18\x01 \x01(\tR\x06openid2\x81\x02\n" +
|
||||
"\x06openid\x18\x01 \x01(\tR\x06openid\"N\n" +
|
||||
"\fUserItemsReq\x12\x16\n" +
|
||||
"\x06mobile\x18\x01 \x01(\tR\x06mobile\x12\x12\n" +
|
||||
"\x04page\x18\x02 \x01(\x05R\x04page\x12\x12\n" +
|
||||
"\x04size\x18\x03 \x01(\x05R\x04size\"7\n" +
|
||||
"\rUserStatusReq\x12\x0e\n" +
|
||||
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x16\n" +
|
||||
"\x06status\x18\x02 \x01(\x05R\x06status2\xa8\x03\n" +
|
||||
"\x04User\x12O\n" +
|
||||
"\bRegister\x12\x11.user.RegisterReq\x1a\x0e.user.Response\" \x82\xd3\xe4\x93\x02\x1a:\x01*\"\x15/customer/v3/register\x12`\n" +
|
||||
"\x0eRegisterByUser\x12\x17.user.RegisterByUserReq\x1a\x0e.user.Response\"%\x82\xd3\xe4\x93\x02\x1f:\x01*\"\x1a/customer/v3/register/user\x12F\n" +
|
||||
"\x05Login\x12\x0e.user.LoginReq\x1a\x0e.user.Response\"\x1d\x82\xd3\xe4\x93\x02\x17:\x01*\"\x12/customer/v3/loginB\bZ\x06./userb\x06proto3"
|
||||
"\x05Login\x12\x0e.user.LoginReq\x1a\x0e.user.Response\"\x1d\x82\xd3\xe4\x93\x02\x17:\x01*\"\x12/customer/v3/login\x12P\n" +
|
||||
"\tUserItems\x12\x12.user.UserItemsReq\x1a\x0e.user.Response\"\x1f\x82\xd3\xe4\x93\x02\x19:\x01*\x12\x14/admin/v3/user/items\x12S\n" +
|
||||
"\n" +
|
||||
"UserStatus\x12\x13.user.UserStatusReq\x1a\x0e.user.Response\" \x82\xd3\xe4\x93\x02\x1a:\x01*\x1a\x15/admin/v3/user/statusB\bZ\x06./userb\x06proto3"
|
||||
|
||||
var (
|
||||
file_proto_user_proto_rawDescOnce sync.Once
|
||||
@@ -348,22 +472,28 @@ func file_proto_user_proto_rawDescGZIP() []byte {
|
||||
return file_proto_user_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_proto_user_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
|
||||
var file_proto_user_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
|
||||
var file_proto_user_proto_goTypes = []any{
|
||||
(*Response)(nil), // 0: user.Response
|
||||
(*RegisterReq)(nil), // 1: user.RegisterReq
|
||||
(*RegisterByUserReq)(nil), // 2: user.RegisterByUserReq
|
||||
(*LoginReq)(nil), // 3: user.LoginReq
|
||||
(*UserItemsReq)(nil), // 4: user.UserItemsReq
|
||||
(*UserStatusReq)(nil), // 5: user.UserStatusReq
|
||||
}
|
||||
var file_proto_user_proto_depIdxs = []int32{
|
||||
1, // 0: user.User.Register:input_type -> user.RegisterReq
|
||||
2, // 1: user.User.RegisterByUser:input_type -> user.RegisterByUserReq
|
||||
3, // 2: user.User.Login:input_type -> user.LoginReq
|
||||
0, // 3: user.User.Register:output_type -> user.Response
|
||||
0, // 4: user.User.RegisterByUser:output_type -> user.Response
|
||||
0, // 5: user.User.Login:output_type -> user.Response
|
||||
3, // [3:6] is the sub-list for method output_type
|
||||
0, // [0:3] is the sub-list for method input_type
|
||||
4, // 3: user.User.UserItems:input_type -> user.UserItemsReq
|
||||
5, // 4: user.User.UserStatus:input_type -> user.UserStatusReq
|
||||
0, // 5: user.User.Register:output_type -> user.Response
|
||||
0, // 6: user.User.RegisterByUser:output_type -> user.Response
|
||||
0, // 7: user.User.Login:output_type -> user.Response
|
||||
0, // 8: user.User.UserItems:output_type -> user.Response
|
||||
0, // 9: user.User.UserStatus:output_type -> user.Response
|
||||
5, // [5:10] is the sub-list for method output_type
|
||||
0, // [0:5] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
@@ -380,7 +510,7 @@ func file_proto_user_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_proto_user_proto_rawDesc), len(file_proto_user_proto_rawDesc)),
|
||||
NumEnums: 0,
|
||||
NumMessages: 4,
|
||||
NumMessages: 6,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
|
||||
@@ -22,6 +22,8 @@ const (
|
||||
User_Register_FullMethodName = "/user.User/Register"
|
||||
User_RegisterByUser_FullMethodName = "/user.User/RegisterByUser"
|
||||
User_Login_FullMethodName = "/user.User/Login"
|
||||
User_UserItems_FullMethodName = "/user.User/UserItems"
|
||||
User_UserStatus_FullMethodName = "/user.User/UserStatus"
|
||||
)
|
||||
|
||||
// UserClient is the client API for User service.
|
||||
@@ -31,6 +33,8 @@ type UserClient interface {
|
||||
Register(ctx context.Context, in *RegisterReq, opts ...grpc.CallOption) (*Response, error)
|
||||
RegisterByUser(ctx context.Context, in *RegisterByUserReq, opts ...grpc.CallOption) (*Response, error)
|
||||
Login(ctx context.Context, in *LoginReq, opts ...grpc.CallOption) (*Response, error)
|
||||
UserItems(ctx context.Context, in *UserItemsReq, opts ...grpc.CallOption) (*Response, error)
|
||||
UserStatus(ctx context.Context, in *UserStatusReq, opts ...grpc.CallOption) (*Response, error)
|
||||
}
|
||||
|
||||
type userClient struct {
|
||||
@@ -71,6 +75,26 @@ func (c *userClient) Login(ctx context.Context, in *LoginReq, opts ...grpc.CallO
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *userClient) UserItems(ctx context.Context, in *UserItemsReq, opts ...grpc.CallOption) (*Response, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Response)
|
||||
err := c.cc.Invoke(ctx, User_UserItems_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *userClient) UserStatus(ctx context.Context, in *UserStatusReq, opts ...grpc.CallOption) (*Response, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Response)
|
||||
err := c.cc.Invoke(ctx, User_UserStatus_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// UserServer is the server API for User service.
|
||||
// All implementations must embed UnimplementedUserServer
|
||||
// for forward compatibility.
|
||||
@@ -78,6 +102,8 @@ type UserServer interface {
|
||||
Register(context.Context, *RegisterReq) (*Response, error)
|
||||
RegisterByUser(context.Context, *RegisterByUserReq) (*Response, error)
|
||||
Login(context.Context, *LoginReq) (*Response, error)
|
||||
UserItems(context.Context, *UserItemsReq) (*Response, error)
|
||||
UserStatus(context.Context, *UserStatusReq) (*Response, error)
|
||||
mustEmbedUnimplementedUserServer()
|
||||
}
|
||||
|
||||
@@ -97,6 +123,12 @@ func (UnimplementedUserServer) RegisterByUser(context.Context, *RegisterByUserRe
|
||||
func (UnimplementedUserServer) Login(context.Context, *LoginReq) (*Response, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method Login not implemented")
|
||||
}
|
||||
func (UnimplementedUserServer) UserItems(context.Context, *UserItemsReq) (*Response, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method UserItems not implemented")
|
||||
}
|
||||
func (UnimplementedUserServer) UserStatus(context.Context, *UserStatusReq) (*Response, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method UserStatus not implemented")
|
||||
}
|
||||
func (UnimplementedUserServer) mustEmbedUnimplementedUserServer() {}
|
||||
func (UnimplementedUserServer) testEmbeddedByValue() {}
|
||||
|
||||
@@ -172,6 +204,42 @@ func _User_Login_Handler(srv interface{}, ctx context.Context, dec func(interfac
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _User_UserItems_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UserItemsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UserServer).UserItems(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: User_UserItems_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UserServer).UserItems(ctx, req.(*UserItemsReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _User_UserStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UserStatusReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UserServer).UserStatus(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: User_UserStatus_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UserServer).UserStatus(ctx, req.(*UserStatusReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// User_ServiceDesc is the grpc.ServiceDesc for User service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
@@ -191,6 +259,14 @@ var User_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "Login",
|
||||
Handler: _User_Login_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "UserItems",
|
||||
Handler: _User_UserItems_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "UserStatus",
|
||||
Handler: _User_UserStatus_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "proto/user.proto",
|
||||
|
||||
+15
-1
@@ -2,7 +2,7 @@
|
||||
// goctl 1.10.1
|
||||
// Source: user.proto
|
||||
|
||||
package userClient
|
||||
package userclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -18,11 +18,15 @@ type (
|
||||
RegisterByUserReq = user.RegisterByUserReq
|
||||
RegisterReq = user.RegisterReq
|
||||
Response = user.Response
|
||||
UserItemsReq = user.UserItemsReq
|
||||
UserStatusReq = user.UserStatusReq
|
||||
|
||||
User interface {
|
||||
Register(ctx context.Context, in *RegisterReq, opts ...grpc.CallOption) (*Response, error)
|
||||
RegisterByUser(ctx context.Context, in *RegisterByUserReq, opts ...grpc.CallOption) (*Response, error)
|
||||
Login(ctx context.Context, in *LoginReq, opts ...grpc.CallOption) (*Response, error)
|
||||
UserItems(ctx context.Context, in *UserItemsReq, opts ...grpc.CallOption) (*Response, error)
|
||||
UserStatus(ctx context.Context, in *UserStatusReq, opts ...grpc.CallOption) (*Response, error)
|
||||
}
|
||||
|
||||
defaultUser struct {
|
||||
@@ -50,3 +54,13 @@ func (m *defaultUser) Login(ctx context.Context, in *LoginReq, opts ...grpc.Call
|
||||
client := user.NewUserClient(m.cli.Conn())
|
||||
return client.Login(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultUser) UserItems(ctx context.Context, in *UserItemsReq, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := user.NewUserClient(m.cli.Conn())
|
||||
return client.UserItems(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultUser) UserStatus(ctx context.Context, in *UserStatusReq, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := user.NewUserClient(m.cli.Conn())
|
||||
return client.UserStatus(ctx, in, opts...)
|
||||
}
|
||||
|
||||
@@ -54,3 +54,30 @@ func (p LoginValidator) GetMessage() validate.ValidatorMessages {
|
||||
"Openid.required": "Openid不能为空",
|
||||
}
|
||||
}
|
||||
|
||||
type UserItemsValidator struct {
|
||||
Mobile string
|
||||
Page int32 `validate:"omitempty,min=1"`
|
||||
Size int32 `validate:"omitempty,min=1,max=100"`
|
||||
}
|
||||
|
||||
func (p UserItemsValidator) GetMessage() validate.ValidatorMessages {
|
||||
return validate.ValidatorMessages{
|
||||
"Page.min": "页码最小为1",
|
||||
"Size.min": "每页数量最小为1",
|
||||
"Size.max": "每页数量最大为100",
|
||||
}
|
||||
}
|
||||
|
||||
type UserStatusValidator struct {
|
||||
Id int64 `validate:"required"`
|
||||
Status int32 `validate:"required,oneof=1 2"`
|
||||
}
|
||||
|
||||
func (p UserStatusValidator) GetMessage() validate.ValidatorMessages {
|
||||
return validate.ValidatorMessages{
|
||||
"Id.required": "用户ID不能为空",
|
||||
"Status.required": "状态不能为空",
|
||||
"Status.oneof": "状态传值不对",
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user