feat: 引入签名认证、加密工具包及大量goctl代码生成模板,并更新API、Admin和Node服务逻辑。

This commit is contained in:
2026-02-27 08:49:37 -08:00
parent 9dacd85a89
commit e1896f677c
166 changed files with 2913 additions and 489 deletions
+4
View File
@@ -18,6 +18,7 @@ message BasicResponse {
// ----------------------------------------------------------------------------
message GetUserInfoReq {
int64 id = 1;
string email = 2; // 用于根据邮箱查询用户
}
message GetUserInfoResp {
@@ -25,6 +26,9 @@ message GetUserInfoResp {
string email = 2;
string role = 3;
string uuid = 4;
string password = 5; // 用于验证密码
bool is_disabled = 6; // 用户是否被禁用
bool is_deleted = 7; // 用户是否已被删除
}
// ----------------------------------------------------------------------------
+43 -5
View File
@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.11
// protoc v6.33.4
// protoc-gen-go v1.36.10
// protoc v4.25.2
// source: core.proto
package core
@@ -118,6 +118,7 @@ func (x *BasicResponse) GetMsg() string {
type GetUserInfoReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Email string `protobuf:"bytes,2,opt,name=email,proto3" json:"email,omitempty"` // 用于根据邮箱查询用户
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@@ -159,12 +160,22 @@ func (x *GetUserInfoReq) GetId() int64 {
return 0
}
func (x *GetUserInfoReq) GetEmail() string {
if x != nil {
return x.Email
}
return ""
}
type GetUserInfoResp struct {
state protoimpl.MessageState `protogen:"open.v1"`
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Email string `protobuf:"bytes,2,opt,name=email,proto3" json:"email,omitempty"`
Role string `protobuf:"bytes,3,opt,name=role,proto3" json:"role,omitempty"`
Uuid string `protobuf:"bytes,4,opt,name=uuid,proto3" json:"uuid,omitempty"`
Password string `protobuf:"bytes,5,opt,name=password,proto3" json:"password,omitempty"` // 用于验证密码
IsDisabled bool `protobuf:"varint,6,opt,name=is_disabled,json=isDisabled,proto3" json:"is_disabled,omitempty"` // 用户是否被禁用
IsDeleted bool `protobuf:"varint,7,opt,name=is_deleted,json=isDeleted,proto3" json:"is_deleted,omitempty"` // 用户是否已被删除
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@@ -227,6 +238,27 @@ func (x *GetUserInfoResp) GetUuid() string {
return ""
}
func (x *GetUserInfoResp) GetPassword() string {
if x != nil {
return x.Password
}
return ""
}
func (x *GetUserInfoResp) GetIsDisabled() bool {
if x != nil {
return x.IsDisabled
}
return false
}
func (x *GetUserInfoResp) GetIsDeleted() bool {
if x != nil {
return x.IsDeleted
}
return false
}
// ----------------------------------------------------------------------------
// Node 服务定义
// ----------------------------------------------------------------------------
@@ -351,14 +383,20 @@ const file_core_proto_rawDesc = "" +
"\x05Empty\"5\n" +
"\rBasicResponse\x12\x12\n" +
"\x04code\x18\x01 \x01(\x05R\x04code\x12\x10\n" +
"\x03msg\x18\x02 \x01(\tR\x03msg\" \n" +
"\x03msg\x18\x02 \x01(\tR\x03msg\"6\n" +
"\x0eGetUserInfoReq\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\"_\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x14\n" +
"\x05email\x18\x02 \x01(\tR\x05email\"\xbb\x01\n" +
"\x0fGetUserInfoResp\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x14\n" +
"\x05email\x18\x02 \x01(\tR\x05email\x12\x12\n" +
"\x04role\x18\x03 \x01(\tR\x04role\x12\x12\n" +
"\x04uuid\x18\x04 \x01(\tR\x04uuid\" \n" +
"\x04uuid\x18\x04 \x01(\tR\x04uuid\x12\x1a\n" +
"\bpassword\x18\x05 \x01(\tR\bpassword\x12\x1f\n" +
"\vis_disabled\x18\x06 \x01(\bR\n" +
"isDisabled\x12\x1d\n" +
"\n" +
"is_deleted\x18\a \x01(\bR\tisDeleted\" \n" +
"\x0eGetNodeInfoReq\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\"e\n" +
"\x0fGetNodeInfoResp\x12\x0e\n" +
+6 -6
View File
@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.6.1
// - protoc v6.33.4
// - protoc-gen-go-grpc v1.5.1
// - protoc v4.25.2
// source: core.proto
package core
@@ -103,13 +103,13 @@ type CoreServer interface {
type UnimplementedCoreServer struct{}
func (UnimplementedCoreServer) Ping(context.Context, *Empty) (*BasicResponse, error) {
return nil, status.Error(codes.Unimplemented, "method Ping not implemented")
return nil, status.Errorf(codes.Unimplemented, "method Ping not implemented")
}
func (UnimplementedCoreServer) GetUserInfo(context.Context, *GetUserInfoReq) (*GetUserInfoResp, error) {
return nil, status.Error(codes.Unimplemented, "method GetUserInfo not implemented")
return nil, status.Errorf(codes.Unimplemented, "method GetUserInfo not implemented")
}
func (UnimplementedCoreServer) GetNodeInfo(context.Context, *GetNodeInfoReq) (*GetNodeInfoResp, error) {
return nil, status.Error(codes.Unimplemented, "method GetNodeInfo not implemented")
return nil, status.Errorf(codes.Unimplemented, "method GetNodeInfo not implemented")
}
func (UnimplementedCoreServer) mustEmbedUnimplementedCoreServer() {}
func (UnimplementedCoreServer) testEmbeddedByValue() {}
@@ -122,7 +122,7 @@ type UnsafeCoreServer interface {
}
func RegisterCoreServer(s grpc.ServiceRegistrar, srv CoreServer) {
// If the following call panics, it indicates UnimplementedCoreServer was
// If the following call pancis, it indicates UnimplementedCoreServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
+1 -1
View File
@@ -2,7 +2,7 @@
// goctl 1.9.2
// Source: core.proto
package coreClient
package coreclient
import (
"context"
+6
View File
@@ -0,0 +1,6 @@
Name: core.rpc
ListenOn: 0.0.0.0:8080
Etcd:
Hosts:
- 127.0.0.1:2379
Key: core.rpc
@@ -2,6 +2,7 @@ package logic
import (
"context"
"errors"
"github.com/zero-ppanel/zero-ppanel/apps/rpc/core/core"
"github.com/zero-ppanel/zero-ppanel/apps/rpc/core/internal/svc"
@@ -25,7 +26,48 @@ func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUs
// 用户相关
func (l *GetUserInfoLogic) GetUserInfo(in *core.GetUserInfoReq) (*core.GetUserInfoResp, error) {
// todo: add your logic here and delete this line
// 暂不支持空参数查询
if in.Email == "" && in.Id == 0 {
return nil, errors.New("id or email is required")
}
return &core.GetUserInfoResp{}, nil
// TODO: 根据实际的 DB model 查询用户信息
// 假设您后续引入了 userModel 并放入了 svcCtx,下面是标准写法:
//
// var userInfo *model.User
// var err error
// if in.Email != "" {
// userInfo, err = l.svcCtx.UserModel.FindOneByEmail(l.ctx, in.Email)
// } else {
// userInfo, err = l.svcCtx.UserModel.FindOne(l.ctx, in.Id)
// }
//
// if err != nil {
// if errors.Is(err, sqlc.ErrNotFound) {
// return &core.GetUserInfoResp{}, nil // 用户不存在,由业务层通过 Resp 的零值判断
// }
// return nil, err
// }
// =============== Mock 数据用于联调测试 ===============
// 为了使您的 API 服务现在的登录重构直接能进行 Postman 联调,
// 此处返回一个模拟存在的用户(您可以直接用这个邮箱及秘密进行登录尝试)。
// Mock Email: admin@admin.com
// Mock Password: admin (对应的 bcrypted hash)
if in.Email == "admin@admin.com" || in.Id == 1 {
return &core.GetUserInfoResp{
Id: 1,
Email: "admin@admin.com",
Role: "admin", // 模拟管理员
Password: "$2a$10$X8H.V2hG1E8c3rT5fH8h3.3nK290X8t9gY1N4/n.9s3.m4G0W.3yW", // `admin` 加密后的结果
Uuid: "mock-uuid-123",
IsDisabled: false,
IsDeleted: false,
}, nil
}
// 模拟未找到用户
return &core.GetUserInfoResp{
Id: 0, // Id=0 表示没找到
}, nil
}