diff --git a/code/base-project/base-app/src/request/api/auth.ts b/code/base-project/base-app/src/request/api/auth.ts index 30b3f117..ff111604 100644 --- a/code/base-project/base-app/src/request/api/auth.ts +++ b/code/base-project/base-app/src/request/api/auth.ts @@ -1,28 +1,12 @@ +import type { LoginDefaultParams, LoginDefaultResult, RegisterDefaultParams } from '@/types/auth' import alovaInstance from '../index' const API_PREFIX = '/auth' -interface RegisterDefaultParams { - account: string - password: string -} - export function registerDefaultApi(params: RegisterDefaultParams) { return alovaInstance.Post>(`${API_PREFIX}/register/default`, params) } -interface LoginDefaultParams { - account: string - password: string -} -interface LoginDefaultResult { - token: string - refreshToken: string - userId: number - username: string - seqNo: number - gender: number -} export function loginDefaultApi(params: LoginDefaultParams) { return alovaInstance.Post>(`${API_PREFIX}/login/default`, params) } diff --git a/code/base-project/base-app/src/request/index.ts b/code/base-project/base-app/src/request/index.ts index eae5f467..e7c263fa 100644 --- a/code/base-project/base-app/src/request/index.ts +++ b/code/base-project/base-app/src/request/index.ts @@ -1,5 +1,6 @@ import type { Method } from 'alova' import type { AxiosError } from 'axios' +import type { RefreshTokenResult } from '@/types/auth' import { axiosRequestAdapter } from '@alova/adapter-axios' import { createAlova } from 'alova' import { router } from 'expo-router' @@ -62,11 +63,11 @@ const alovaInstance = createAlova({ } // 调用刷新接口 - const res = await alovaInstance.Get>('/auth/refresh/token', { + const res = await alovaInstance.Get>('/auth/refreshToken', { headers: { refreshToken }, }).send() - const newToken = res.data + const newToken = res.data.refreshToken // 更新 store useUserStore.getState().setUserInfo({ diff --git a/code/base-project/base-app/src/store/moneyCategory.ts b/code/base-project/base-app/src/store/moneyCategory.ts index 3131aa6c..f22464c7 100644 --- a/code/base-project/base-app/src/store/moneyCategory.ts +++ b/code/base-project/base-app/src/store/moneyCategory.ts @@ -44,7 +44,7 @@ export const useMoneyCategoryStore = create()( try { const res = await queryMoneyCategoryApi() if (res.isSuccess) { - set({ categories: res.data || [] }) + set({ categories: res.data.categories || [] }) } } catch (e) { diff --git a/code/base-project/base-app/src/types/auth.ts b/code/base-project/base-app/src/types/auth.ts new file mode 100644 index 00000000..65118857 --- /dev/null +++ b/code/base-project/base-app/src/types/auth.ts @@ -0,0 +1,22 @@ +export interface RefreshTokenResult { + refreshToken: string +} + +export interface RegisterDefaultParams { + account: string + password: string +} + +export interface LoginDefaultParams { + account: string + password: string +} + +export interface LoginDefaultResult { + token: string + refreshToken: string + userId: number + username: string + seqNo: number + gender: number +} diff --git a/code/base-project/base-app/src/types/money/category.ts b/code/base-project/base-app/src/types/money/category.ts index 3e7bd2a8..a0d37e75 100644 --- a/code/base-project/base-app/src/types/money/category.ts +++ b/code/base-project/base-app/src/types/money/category.ts @@ -8,11 +8,13 @@ export interface MoneyCategoryBase { } // 查询 -export interface MoneyCategoryItem extends MoneyCategoryBase { +export interface MoneyCategoryItem extends Omit { } -export type QueryMoneyCategoryResult = MoneyCategoryBase[] +export interface QueryMoneyCategoryResult { + categories: MoneyCategoryItem[] +} export interface DeleteMoneyCategoryParams { id: number diff --git a/code/base-project/base-go-v3/biz/handler/auth/login_service.go b/code/base-project/base-go-v3/biz/handler/auth/login_service.go new file mode 100644 index 00000000..5279a2a5 --- /dev/null +++ b/code/base-project/base-go-v3/biz/handler/auth/login_service.go @@ -0,0 +1,66 @@ +// Code generated by hertz generator. + +package auth + +import ( + "cn/oneao/base-go/db" + dbtype "cn/oneao/base-go/db/sqlc" + "cn/oneao/base-go/logx" + "cn/oneao/base-go/utils/jwtx" + "cn/oneao/base-go/utils/response" + "context" + + "cn/oneao/base-go/biz/model/auth" + "github.com/cloudwego/hertz/pkg/app" + "github.com/cloudwego/hertz/pkg/protocol/consts" +) + +// LoginDefault . +// @router /auth/login/default [POST] +func LoginDefault(ctx context.Context, c *app.RequestContext) { + var err error + var req auth.LoginDefaultReq + err = c.BindAndValidate(&req) + if err != nil { + c.String(consts.StatusBadRequest, err.Error()) + return + } + + // 登录 + account := req.Account + password := req.Password + + params := dbtype.GetUserForLoginParams{ + Account: account, + Password: password, + } + loginUser, err := db.Queries.GetUserForLogin(ctx, params) + + if err != nil { + response.Fail(c).Message("账号或密码错误!").Send() + return + } + + // 异步更新登录事件 + go func(userID int64) { + time, err := db.Queries.UpdateUserLoginLastTime(ctx, userID) + if err != nil || time == 0 { + logx.CtxError(ctx, "更新用户登录时间失败,UserID=%d, err=%v", loginUser.ID, err) + } + }(loginUser.ID) + + // 包装数据 + token, err := jwtx.CreateAccessToken(loginUser.ID) + refreshToken, err := jwtx.CreateRefreshToken(loginUser.ID) + + resp := new(auth.LoginDefaultResp) + + resp.Token = token + resp.RefreshToken = refreshToken + resp.UserId = loginUser.ID + resp.Gender = loginUser.Gender.Int32 + resp.SeqNo = loginUser.SeqNo.Int32 + resp.Username = loginUser.Username.String + + response.Success(c).Data(resp).Send() +} diff --git a/code/base-project/base-go-v3/biz/handler/auth/register_service.go b/code/base-project/base-go-v3/biz/handler/auth/register_service.go new file mode 100644 index 00000000..ebf6fe66 --- /dev/null +++ b/code/base-project/base-go-v3/biz/handler/auth/register_service.go @@ -0,0 +1,118 @@ +// Code generated by hertz generator. + +package auth + +import ( + auth "cn/oneao/base-go/biz/model/auth" + "cn/oneao/base-go/db" + dbtype "cn/oneao/base-go/db/sqlc" + "cn/oneao/base-go/utils/errorx" + "cn/oneao/base-go/utils/idgen" + "cn/oneao/base-go/utils/response" + "context" + "github.com/cloudwego/hertz/pkg/app" + "github.com/cloudwego/hertz/pkg/protocol/consts" + "github.com/jackc/pgx/v5" +) + +// RegisterDefault . +// @router /auth/register/default [POST] +func RegisterDefault(ctx context.Context, c *app.RequestContext) { + var err error + var req auth.RegisterDefaultReq + err = c.BindAndValidate(&req) + if err != nil { + c.String(consts.StatusBadRequest, err.Error()) + return + } + + account := req.Account + password := req.Password + + _, err = db.Queries.GetUserByAccount(ctx, account) + if err != nil { + if errorx.IsNotFound(err) { + // 忽略 + } else { + errorx.AddError(c, err) + return + } + } else { + response.Fail(c).Message("该账号已被注册").Send() + return + } + + // 开启事务 + tx, err := db.DB.BeginTx(ctx, pgx.TxOptions{}) + if err != nil { + errorx.AddError(c, err) + return + } + + defer func() { + if err != nil { + err := tx.Rollback(ctx) + if err != nil { + return + } + } else { + err := tx.Commit(ctx) + if err != nil { + return + } + } + }() + + // 插入用户 + params := dbtype.InsertUserParams{ + ID: idgen.NextId(), + Account: account, + Password: password, + } + + insert, err := db.Queries.WithTx(tx).InsertUser(ctx, params) + if err != nil || insert == 0 { + errorx.AddError(c, err) + return + } + + // 初始化用户分类 + err = initMoneyCategoryTx(ctx, tx, params.ID) + if err != nil { + errorx.AddError(c, err) + return + } + + // 注册成功 + response.Success(c).Message("注册成功").Send() +} + +func initMoneyCategoryTx(ctx context.Context, tx pgx.Tx, userId int64) error { + sysCategories, err := db.Queries.ListMoneySysCategory(ctx) + if err != nil { + return err + } + if len(sysCategories) == 0 { + return nil + } + + userCategories := make([]dbtype.BatchInsertMoneyUserCategoriesParams, 0, len(sysCategories)) + for _, sysCat := range sysCategories { + userCategories = append(userCategories, dbtype.BatchInsertMoneyUserCategoriesParams{ + ID: idgen.NextId(), + UserID: userId, + Name: sysCat.Name, + Icon: sysCat.Icon, + Type: sysCat.Type, + SortNumber: sysCat.SortNumber, + }) + } + + _, err = db.Queries.WithTx(tx).BatchInsertMoneyUserCategories(ctx, userCategories) + + if err != nil { + return err + } + + return nil +} diff --git a/code/base-project/base-go-v3/biz/handler/auth/token_service.go b/code/base-project/base-go-v3/biz/handler/auth/token_service.go new file mode 100644 index 00000000..f3571a87 --- /dev/null +++ b/code/base-project/base-go-v3/biz/handler/auth/token_service.go @@ -0,0 +1,59 @@ +// Code generated by hertz generator. + +package auth + +import ( + "cn/oneao/base-go/utils/errorx" + "cn/oneao/base-go/utils/jwtx" + "cn/oneao/base-go/utils/response" + "context" + + auth "cn/oneao/base-go/biz/model/auth" + "github.com/cloudwego/hertz/pkg/app" + "github.com/cloudwego/hertz/pkg/protocol/consts" +) + +// RefreshAccessToken . +// @router /auth/refreshToken [POST] +func RefreshAccessToken(ctx context.Context, c *app.RequestContext) { + var err error + var req auth.RefreshAccessTokenReq + err = c.BindAndValidate(&req) + if err != nil { + c.String(consts.StatusBadRequest, err.Error()) + return + } + + refreshToken := string(c.GetHeader("refreshToken")) + if refreshToken == "" { + response.Fail(c). + Code(response.HttpCode.Unauthorized). + Send() + return + } + + tokenResult := jwtx.VerifyToken(refreshToken) + + if !tokenResult.IsValid || tokenResult.IsExpired { + // Refresh Token 无效或过期,需要重新登录 + response.Fail(c). + Code(response.HttpCode.Unauthorized). + Send() + return + } + + userID := tokenResult.Claims.UserID + // 生成新的 Access Token + newAccessToken, err := jwtx.CreateAccessToken(userID) + if err != nil { + errorx.AddError(c, err) + return + } + + resp := new(auth.RefreshAccessTokenResp) + resp.AccessToken = newAccessToken + + response.Success(c). + Data(resp). + Send() +} diff --git a/code/base-project/base-go-v3/biz/handler/login/login_service.go b/code/base-project/base-go-v3/biz/handler/login/login_service.go deleted file mode 100644 index 07c08faa..00000000 --- a/code/base-project/base-go-v3/biz/handler/login/login_service.go +++ /dev/null @@ -1,27 +0,0 @@ -// Code generated by hertz generator. - -package login - -import ( - "context" - - login "cn/oneao/base-go/biz/model/auth/login" - "github.com/cloudwego/hertz/pkg/app" - "github.com/cloudwego/hertz/pkg/protocol/consts" -) - -// LoginDefault . -// @router /auth/login/default [POST] -func LoginDefault(ctx context.Context, c *app.RequestContext) { - var err error - var req login.LoginDefaultReq - err = c.BindAndValidate(&req) - if err != nil { - c.String(consts.StatusBadRequest, err.Error()) - return - } - - resp := new(login.LoginDefaultResp) - - c.JSON(consts.StatusOK, resp) -} diff --git a/code/base-project/base-go-v3/biz/handler/money_category/money_category_service.go b/code/base-project/base-go-v3/biz/handler/money_category/money_category_service.go new file mode 100644 index 00000000..ddda0f61 --- /dev/null +++ b/code/base-project/base-go-v3/biz/handler/money_category/money_category_service.go @@ -0,0 +1,54 @@ +// Code generated by hertz generator. + +package money_category + +import ( + money_category "cn/oneao/base-go/biz/model/money_category" + "cn/oneao/base-go/biz/router/middleware" + "cn/oneao/base-go/db" + "cn/oneao/base-go/utils/errorx" + "cn/oneao/base-go/utils/response" + "context" + "github.com/cloudwego/hertz/pkg/app" + "github.com/cloudwego/hertz/pkg/protocol/consts" +) + +// QueryUserMoneyCategory . +// @router /money/category [GET] +func QueryUserMoneyCategory(ctx context.Context, c *app.RequestContext) { + var err error + var req money_category.QueryUserMoneyCategoryReq + err = c.BindAndValidate(&req) + if err != nil { + c.String(consts.StatusBadRequest, err.Error()) + return + } + + userID := middleware.GetUserID(ctx) + + // 查询用户分类 + moneyUserCategories, err := db.Queries.FindUserMoneyCategoriesByUserID(ctx, userID) + if err != nil { + errorx.AddError(c, err) + return + } + + // 构造返回数据,切片类型是 []*UserMoneyCategory + resp := &money_category.QueryUserMoneyCategoryResp{ + Categories: make([]*money_category.UserMoneyCategory, 0, len(moneyUserCategories)), + } + + for _, c := range moneyUserCategories { + category := &money_category.UserMoneyCategory{ + Id: c.ID, + Name: c.Name, + Icon: c.Icon, + + Type: c.Type.Int32, + SortNumber: c.SortNumber.Int32, + } + resp.Categories = append(resp.Categories, category) + } + + response.Success(c).Data(resp).Send() +} diff --git a/code/base-project/base-go-v3/biz/handler/register/register_service.go b/code/base-project/base-go-v3/biz/handler/register/register_service.go deleted file mode 100644 index 556c692e..00000000 --- a/code/base-project/base-go-v3/biz/handler/register/register_service.go +++ /dev/null @@ -1,27 +0,0 @@ -// Code generated by hertz generator. - -package register - -import ( - "context" - - register "cn/oneao/base-go/biz/model/auth/register" - "github.com/cloudwego/hertz/pkg/app" - "github.com/cloudwego/hertz/pkg/protocol/consts" -) - -// RegisterDefault . -// @router /auth/register/default [POST] -func RegisterDefault(ctx context.Context, c *app.RequestContext) { - var err error - var req register.RegisterDefaultReq - err = c.BindAndValidate(&req) - if err != nil { - c.String(consts.StatusBadRequest, err.Error()) - return - } - - resp := new(register.RegisterDefaultResp) - - c.JSON(consts.StatusOK, resp) -} diff --git a/code/base-project/base-go-v3/biz/model/api/api.pb.go b/code/base-project/base-go-v3/biz/model/api/api.pb.go index 37434df6..09470162 100644 --- a/code/base-project/base-go-v3/biz/model/api/api.pb.go +++ b/code/base-project/base-go-v3/biz/model/api/api.pb.go @@ -3,7 +3,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.28.0 -// protoc v6.33.1 +// protoc v4.25.3 // source: api.proto package api diff --git a/code/base-project/base-go-v3/biz/model/auth/auth.pb.go b/code/base-project/base-go-v3/biz/model/auth/auth.pb.go new file mode 100644 index 00000000..87d53375 --- /dev/null +++ b/code/base-project/base-go-v3/biz/model/auth/auth.pb.go @@ -0,0 +1,540 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v4.25.3 +// source: auth.proto + +package auth + +import ( + _ "cn/oneao/base-go/biz/model/api" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type LoginDefaultReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Account string `protobuf:"bytes,1,opt,name=Account,proto3" form:"account" json:"account" vd:"$!=''"` + Password string `protobuf:"bytes,2,opt,name=Password,proto3" form:"password" json:"password" vd:"$!=''"` +} + +func (x *LoginDefaultReq) Reset() { + *x = LoginDefaultReq{} + if protoimpl.UnsafeEnabled { + mi := &file_auth_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LoginDefaultReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LoginDefaultReq) ProtoMessage() {} + +func (x *LoginDefaultReq) ProtoReflect() protoreflect.Message { + mi := &file_auth_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LoginDefaultReq.ProtoReflect.Descriptor instead. +func (*LoginDefaultReq) Descriptor() ([]byte, []int) { + return file_auth_proto_rawDescGZIP(), []int{0} +} + +func (x *LoginDefaultReq) GetAccount() string { + if x != nil { + return x.Account + } + return "" +} + +func (x *LoginDefaultReq) GetPassword() string { + if x != nil { + return x.Password + } + return "" +} + +type LoginDefaultResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Token string `protobuf:"bytes,1,opt,name=token,proto3" form:"token" json:"token" query:"token"` + RefreshToken string `protobuf:"bytes,2,opt,name=refreshToken,proto3" form:"refreshToken" json:"refreshToken" query:"refreshToken"` + UserId int64 `protobuf:"varint,3,opt,name=userId,proto3" form:"userId" json:"userId" query:"userId"` + Username string `protobuf:"bytes,4,opt,name=username,proto3" form:"username" json:"username" query:"username"` + SeqNo int32 `protobuf:"varint,5,opt,name=seqNo,proto3" form:"seqNo" json:"seqNo" query:"seqNo"` + Gender int32 `protobuf:"varint,6,opt,name=gender,proto3" form:"gender" json:"gender" query:"gender"` +} + +func (x *LoginDefaultResp) Reset() { + *x = LoginDefaultResp{} + if protoimpl.UnsafeEnabled { + mi := &file_auth_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LoginDefaultResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LoginDefaultResp) ProtoMessage() {} + +func (x *LoginDefaultResp) ProtoReflect() protoreflect.Message { + mi := &file_auth_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LoginDefaultResp.ProtoReflect.Descriptor instead. +func (*LoginDefaultResp) Descriptor() ([]byte, []int) { + return file_auth_proto_rawDescGZIP(), []int{1} +} + +func (x *LoginDefaultResp) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +func (x *LoginDefaultResp) GetRefreshToken() string { + if x != nil { + return x.RefreshToken + } + return "" +} + +func (x *LoginDefaultResp) GetUserId() int64 { + if x != nil { + return x.UserId + } + return 0 +} + +func (x *LoginDefaultResp) GetUsername() string { + if x != nil { + return x.Username + } + return "" +} + +func (x *LoginDefaultResp) GetSeqNo() int32 { + if x != nil { + return x.SeqNo + } + return 0 +} + +func (x *LoginDefaultResp) GetGender() int32 { + if x != nil { + return x.Gender + } + return 0 +} + +type RegisterDefaultReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Account string `protobuf:"bytes,1,opt,name=Account,proto3" form:"account" json:"account" vd:"$!=''"` + Password string `protobuf:"bytes,2,opt,name=Password,proto3" form:"password" json:"password" vd:"$!=''"` +} + +func (x *RegisterDefaultReq) Reset() { + *x = RegisterDefaultReq{} + if protoimpl.UnsafeEnabled { + mi := &file_auth_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RegisterDefaultReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RegisterDefaultReq) ProtoMessage() {} + +func (x *RegisterDefaultReq) ProtoReflect() protoreflect.Message { + mi := &file_auth_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RegisterDefaultReq.ProtoReflect.Descriptor instead. +func (*RegisterDefaultReq) Descriptor() ([]byte, []int) { + return file_auth_proto_rawDescGZIP(), []int{2} +} + +func (x *RegisterDefaultReq) GetAccount() string { + if x != nil { + return x.Account + } + return "" +} + +func (x *RegisterDefaultReq) GetPassword() string { + if x != nil { + return x.Password + } + return "" +} + +type RegisterDefaultResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *RegisterDefaultResp) Reset() { + *x = RegisterDefaultResp{} + if protoimpl.UnsafeEnabled { + mi := &file_auth_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RegisterDefaultResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RegisterDefaultResp) ProtoMessage() {} + +func (x *RegisterDefaultResp) ProtoReflect() protoreflect.Message { + mi := &file_auth_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RegisterDefaultResp.ProtoReflect.Descriptor instead. +func (*RegisterDefaultResp) Descriptor() ([]byte, []int) { + return file_auth_proto_rawDescGZIP(), []int{3} +} + +type RefreshAccessTokenReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *RefreshAccessTokenReq) Reset() { + *x = RefreshAccessTokenReq{} + if protoimpl.UnsafeEnabled { + mi := &file_auth_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RefreshAccessTokenReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RefreshAccessTokenReq) ProtoMessage() {} + +func (x *RefreshAccessTokenReq) ProtoReflect() protoreflect.Message { + mi := &file_auth_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RefreshAccessTokenReq.ProtoReflect.Descriptor instead. +func (*RefreshAccessTokenReq) Descriptor() ([]byte, []int) { + return file_auth_proto_rawDescGZIP(), []int{4} +} + +type RefreshAccessTokenResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + AccessToken string `protobuf:"bytes,1,opt,name=accessToken,proto3" form:"accessToken" json:"accessToken" query:"accessToken"` +} + +func (x *RefreshAccessTokenResp) Reset() { + *x = RefreshAccessTokenResp{} + if protoimpl.UnsafeEnabled { + mi := &file_auth_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RefreshAccessTokenResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RefreshAccessTokenResp) ProtoMessage() {} + +func (x *RefreshAccessTokenResp) ProtoReflect() protoreflect.Message { + mi := &file_auth_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RefreshAccessTokenResp.ProtoReflect.Descriptor instead. +func (*RefreshAccessTokenResp) Descriptor() ([]byte, []int) { + return file_auth_proto_rawDescGZIP(), []int{5} +} + +func (x *RefreshAccessTokenResp) GetAccessToken() string { + if x != nil { + return x.AccessToken + } + return "" +} + +var File_auth_proto protoreflect.FileDescriptor + +var file_auth_proto_rawDesc = []byte{ + 0x0a, 0x0a, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x61, 0x75, + 0x74, 0x68, 0x1a, 0x09, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x74, 0x0a, + 0x0f, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x71, + 0x12, 0x2e, 0x0a, 0x07, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x42, 0x14, 0xca, 0xbb, 0x18, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0xda, 0xbb, + 0x18, 0x05, 0x24, 0x21, 0x3d, 0x27, 0x27, 0x52, 0x07, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x12, 0x31, 0x0a, 0x08, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x42, 0x15, 0xca, 0xbb, 0x18, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, + 0xda, 0xbb, 0x18, 0x05, 0x24, 0x21, 0x3d, 0x27, 0x27, 0x52, 0x08, 0x50, 0x61, 0x73, 0x73, 0x77, + 0x6f, 0x72, 0x64, 0x22, 0xae, 0x01, 0x0a, 0x10, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x44, 0x65, 0x66, + 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, + 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x22, + 0x0a, 0x0c, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, + 0x65, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, + 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, + 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x65, 0x71, 0x4e, 0x6f, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x65, 0x71, 0x4e, 0x6f, 0x12, 0x16, 0x0a, 0x06, + 0x67, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x67, 0x65, + 0x6e, 0x64, 0x65, 0x72, 0x22, 0x77, 0x0a, 0x12, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, + 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x71, 0x12, 0x2e, 0x0a, 0x07, 0x41, 0x63, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x14, 0xca, 0xbb, 0x18, + 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0xda, 0xbb, 0x18, 0x05, 0x24, 0x21, 0x3d, 0x27, + 0x27, 0x52, 0x07, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x31, 0x0a, 0x08, 0x50, 0x61, + 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x15, 0xca, 0xbb, + 0x18, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0xda, 0xbb, 0x18, 0x05, 0x24, 0x21, + 0x3d, 0x27, 0x27, 0x52, 0x08, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x15, 0x0a, + 0x13, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, + 0x52, 0x65, 0x73, 0x70, 0x22, 0x17, 0x0a, 0x15, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x41, + 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x22, 0x3a, 0x0a, + 0x16, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, + 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x20, 0x0a, 0x0b, 0x61, 0x63, 0x63, 0x65, 0x73, + 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x63, + 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x32, 0x66, 0x0a, 0x0c, 0x4c, 0x6f, 0x67, + 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x56, 0x0a, 0x0c, 0x4c, 0x6f, 0x67, + 0x69, 0x6e, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x15, 0x2e, 0x61, 0x75, 0x74, 0x68, + 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x71, + 0x1a, 0x16, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x44, 0x65, 0x66, + 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x73, 0x70, 0x22, 0x17, 0xd2, 0xc1, 0x18, 0x13, 0x2f, 0x61, + 0x75, 0x74, 0x68, 0x2f, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x2f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, + 0x74, 0x32, 0x75, 0x0a, 0x0f, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x12, 0x62, 0x0a, 0x0f, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, + 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x52, + 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, + 0x71, 0x1a, 0x19, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, + 0x72, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x73, 0x70, 0x22, 0x1a, 0xd2, 0xc1, + 0x18, 0x16, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, + 0x2f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x32, 0x77, 0x0a, 0x0c, 0x54, 0x6f, 0x6b, 0x65, + 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x67, 0x0a, 0x12, 0x52, 0x65, 0x66, 0x72, + 0x65, 0x73, 0x68, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x1b, + 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x41, 0x63, 0x63, + 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x1a, 0x1c, 0x2e, 0x61, 0x75, + 0x74, 0x68, 0x2e, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, + 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x22, 0x16, 0xd2, 0xc1, 0x18, 0x12, 0x2f, + 0x61, 0x75, 0x74, 0x68, 0x2f, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, + 0x6e, 0x42, 0x21, 0x5a, 0x1f, 0x63, 0x6e, 0x2f, 0x6f, 0x6e, 0x65, 0x61, 0x6f, 0x2f, 0x62, 0x61, + 0x73, 0x65, 0x2d, 0x67, 0x6f, 0x2f, 0x62, 0x69, 0x7a, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2f, + 0x61, 0x75, 0x74, 0x68, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_auth_proto_rawDescOnce sync.Once + file_auth_proto_rawDescData = file_auth_proto_rawDesc +) + +func file_auth_proto_rawDescGZIP() []byte { + file_auth_proto_rawDescOnce.Do(func() { + file_auth_proto_rawDescData = protoimpl.X.CompressGZIP(file_auth_proto_rawDescData) + }) + return file_auth_proto_rawDescData +} + +var file_auth_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_auth_proto_goTypes = []interface{}{ + (*LoginDefaultReq)(nil), // 0: auth.LoginDefaultReq + (*LoginDefaultResp)(nil), // 1: auth.LoginDefaultResp + (*RegisterDefaultReq)(nil), // 2: auth.RegisterDefaultReq + (*RegisterDefaultResp)(nil), // 3: auth.RegisterDefaultResp + (*RefreshAccessTokenReq)(nil), // 4: auth.RefreshAccessTokenReq + (*RefreshAccessTokenResp)(nil), // 5: auth.RefreshAccessTokenResp +} +var file_auth_proto_depIdxs = []int32{ + 0, // 0: auth.LoginService.LoginDefault:input_type -> auth.LoginDefaultReq + 2, // 1: auth.RegisterService.RegisterDefault:input_type -> auth.RegisterDefaultReq + 4, // 2: auth.TokenService.RefreshAccessToken:input_type -> auth.RefreshAccessTokenReq + 1, // 3: auth.LoginService.LoginDefault:output_type -> auth.LoginDefaultResp + 3, // 4: auth.RegisterService.RegisterDefault:output_type -> auth.RegisterDefaultResp + 5, // 5: auth.TokenService.RefreshAccessToken:output_type -> auth.RefreshAccessTokenResp + 3, // [3:6] is the sub-list for method output_type + 0, // [0:3] 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 +} + +func init() { file_auth_proto_init() } +func file_auth_proto_init() { + if File_auth_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_auth_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LoginDefaultReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_auth_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LoginDefaultResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_auth_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RegisterDefaultReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_auth_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RegisterDefaultResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_auth_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RefreshAccessTokenReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_auth_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RefreshAccessTokenResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_auth_proto_rawDesc, + NumEnums: 0, + NumMessages: 6, + NumExtensions: 0, + NumServices: 3, + }, + GoTypes: file_auth_proto_goTypes, + DependencyIndexes: file_auth_proto_depIdxs, + MessageInfos: file_auth_proto_msgTypes, + }.Build() + File_auth_proto = out.File + file_auth_proto_rawDesc = nil + file_auth_proto_goTypes = nil + file_auth_proto_depIdxs = nil +} diff --git a/code/base-project/base-go-v3/biz/model/auth/login/login.pb.go b/code/base-project/base-go-v3/biz/model/auth/login/login.pb.go deleted file mode 100644 index e25e9d0f..00000000 --- a/code/base-project/base-go-v3/biz/model/auth/login/login.pb.go +++ /dev/null @@ -1,277 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.28.0 -// protoc v6.33.1 -// source: login.proto - -package login - -import ( - _ "cn/oneao/base-go/biz/model/api" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type LoginDefaultReq struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Account string `protobuf:"bytes,1,opt,name=Account,proto3" form:"account" json:"account" vd:"$!=''"` - Password string `protobuf:"bytes,2,opt,name=Password,proto3" form:"password" json:"password" vd:"$!=''"` -} - -func (x *LoginDefaultReq) Reset() { - *x = LoginDefaultReq{} - if protoimpl.UnsafeEnabled { - mi := &file_login_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *LoginDefaultReq) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*LoginDefaultReq) ProtoMessage() {} - -func (x *LoginDefaultReq) ProtoReflect() protoreflect.Message { - mi := &file_login_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use LoginDefaultReq.ProtoReflect.Descriptor instead. -func (*LoginDefaultReq) Descriptor() ([]byte, []int) { - return file_login_proto_rawDescGZIP(), []int{0} -} - -func (x *LoginDefaultReq) GetAccount() string { - if x != nil { - return x.Account - } - return "" -} - -func (x *LoginDefaultReq) GetPassword() string { - if x != nil { - return x.Password - } - return "" -} - -type LoginDefaultResp struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Token string `protobuf:"bytes,1,opt,name=token,proto3" form:"token" json:"token" query:"token"` - RefreshToken string `protobuf:"bytes,2,opt,name=refreshToken,proto3" form:"refreshToken" json:"refreshToken" query:"refreshToken"` - UserId int64 `protobuf:"varint,3,opt,name=userId,proto3" form:"userId" json:"userId" query:"userId"` - Username string `protobuf:"bytes,4,opt,name=username,proto3" form:"username" json:"username" query:"username"` - SeqNo int64 `protobuf:"varint,5,opt,name=seqNo,proto3" form:"seqNo" json:"seqNo" query:"seqNo"` - Gender int64 `protobuf:"varint,6,opt,name=gender,proto3" form:"gender" json:"gender" query:"gender"` -} - -func (x *LoginDefaultResp) Reset() { - *x = LoginDefaultResp{} - if protoimpl.UnsafeEnabled { - mi := &file_login_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *LoginDefaultResp) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*LoginDefaultResp) ProtoMessage() {} - -func (x *LoginDefaultResp) ProtoReflect() protoreflect.Message { - mi := &file_login_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use LoginDefaultResp.ProtoReflect.Descriptor instead. -func (*LoginDefaultResp) Descriptor() ([]byte, []int) { - return file_login_proto_rawDescGZIP(), []int{1} -} - -func (x *LoginDefaultResp) GetToken() string { - if x != nil { - return x.Token - } - return "" -} - -func (x *LoginDefaultResp) GetRefreshToken() string { - if x != nil { - return x.RefreshToken - } - return "" -} - -func (x *LoginDefaultResp) GetUserId() int64 { - if x != nil { - return x.UserId - } - return 0 -} - -func (x *LoginDefaultResp) GetUsername() string { - if x != nil { - return x.Username - } - return "" -} - -func (x *LoginDefaultResp) GetSeqNo() int64 { - if x != nil { - return x.SeqNo - } - return 0 -} - -func (x *LoginDefaultResp) GetGender() int64 { - if x != nil { - return x.Gender - } - return 0 -} - -var File_login_proto protoreflect.FileDescriptor - -var file_login_proto_rawDesc = []byte{ - 0x0a, 0x0b, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x61, - 0x75, 0x74, 0x68, 0x1a, 0x09, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x74, - 0x0a, 0x0f, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, - 0x71, 0x12, 0x2e, 0x0a, 0x07, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x42, 0x14, 0xca, 0xbb, 0x18, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0xda, - 0xbb, 0x18, 0x05, 0x24, 0x21, 0x3d, 0x27, 0x27, 0x52, 0x07, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x12, 0x31, 0x0a, 0x08, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x42, 0x15, 0xca, 0xbb, 0x18, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, - 0x64, 0xda, 0xbb, 0x18, 0x05, 0x24, 0x21, 0x3d, 0x27, 0x27, 0x52, 0x08, 0x50, 0x61, 0x73, 0x73, - 0x77, 0x6f, 0x72, 0x64, 0x22, 0xae, 0x01, 0x0a, 0x10, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x44, 0x65, - 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, - 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, - 0x22, 0x0a, 0x0c, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, - 0x6b, 0x65, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x03, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x75, - 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, - 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x65, 0x71, 0x4e, 0x6f, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x73, 0x65, 0x71, 0x4e, 0x6f, 0x12, 0x16, 0x0a, - 0x06, 0x67, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x67, - 0x65, 0x6e, 0x64, 0x65, 0x72, 0x32, 0x66, 0x0a, 0x0c, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x53, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x56, 0x0a, 0x0c, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x44, 0x65, - 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x15, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x4c, 0x6f, 0x67, - 0x69, 0x6e, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x16, 0x2e, 0x61, - 0x75, 0x74, 0x68, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, - 0x52, 0x65, 0x73, 0x70, 0x22, 0x17, 0xd2, 0xc1, 0x18, 0x13, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, - 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x2f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x42, 0x27, 0x5a, - 0x25, 0x63, 0x6e, 0x2f, 0x6f, 0x6e, 0x65, 0x61, 0x6f, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2d, 0x67, - 0x6f, 0x2f, 0x62, 0x69, 0x7a, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2f, 0x61, 0x75, 0x74, 0x68, - 0x2f, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_login_proto_rawDescOnce sync.Once - file_login_proto_rawDescData = file_login_proto_rawDesc -) - -func file_login_proto_rawDescGZIP() []byte { - file_login_proto_rawDescOnce.Do(func() { - file_login_proto_rawDescData = protoimpl.X.CompressGZIP(file_login_proto_rawDescData) - }) - return file_login_proto_rawDescData -} - -var file_login_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_login_proto_goTypes = []interface{}{ - (*LoginDefaultReq)(nil), // 0: auth.LoginDefaultReq - (*LoginDefaultResp)(nil), // 1: auth.LoginDefaultResp -} -var file_login_proto_depIdxs = []int32{ - 0, // 0: auth.LoginService.LoginDefault:input_type -> auth.LoginDefaultReq - 1, // 1: auth.LoginService.LoginDefault:output_type -> auth.LoginDefaultResp - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] 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 -} - -func init() { file_login_proto_init() } -func file_login_proto_init() { - if File_login_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_login_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*LoginDefaultReq); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_login_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*LoginDefaultResp); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_login_proto_rawDesc, - NumEnums: 0, - NumMessages: 2, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_login_proto_goTypes, - DependencyIndexes: file_login_proto_depIdxs, - MessageInfos: file_login_proto_msgTypes, - }.Build() - File_login_proto = out.File - file_login_proto_rawDesc = nil - file_login_proto_goTypes = nil - file_login_proto_depIdxs = nil -} diff --git a/code/base-project/base-go-v3/biz/model/auth/register/register.pb.go b/code/base-project/base-go-v3/biz/model/auth/register/register.pb.go deleted file mode 100644 index 215867b1..00000000 --- a/code/base-project/base-go-v3/biz/model/auth/register/register.pb.go +++ /dev/null @@ -1,220 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.28.0 -// protoc v6.33.1 -// source: register.proto - -package register - -import ( - _ "cn/oneao/base-go/biz/model/api" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type RegisterDefaultReq struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Account string `protobuf:"bytes,1,opt,name=Account,proto3" form:"account" json:"account" vd:"$!=''"` - Password string `protobuf:"bytes,2,opt,name=Password,proto3" form:"password" json:"password" vd:"$!=''"` -} - -func (x *RegisterDefaultReq) Reset() { - *x = RegisterDefaultReq{} - if protoimpl.UnsafeEnabled { - mi := &file_register_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *RegisterDefaultReq) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*RegisterDefaultReq) ProtoMessage() {} - -func (x *RegisterDefaultReq) ProtoReflect() protoreflect.Message { - mi := &file_register_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use RegisterDefaultReq.ProtoReflect.Descriptor instead. -func (*RegisterDefaultReq) Descriptor() ([]byte, []int) { - return file_register_proto_rawDescGZIP(), []int{0} -} - -func (x *RegisterDefaultReq) GetAccount() string { - if x != nil { - return x.Account - } - return "" -} - -func (x *RegisterDefaultReq) GetPassword() string { - if x != nil { - return x.Password - } - return "" -} - -type RegisterDefaultResp struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields -} - -func (x *RegisterDefaultResp) Reset() { - *x = RegisterDefaultResp{} - if protoimpl.UnsafeEnabled { - mi := &file_register_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *RegisterDefaultResp) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*RegisterDefaultResp) ProtoMessage() {} - -func (x *RegisterDefaultResp) ProtoReflect() protoreflect.Message { - mi := &file_register_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use RegisterDefaultResp.ProtoReflect.Descriptor instead. -func (*RegisterDefaultResp) Descriptor() ([]byte, []int) { - return file_register_proto_rawDescGZIP(), []int{1} -} - -var File_register_proto protoreflect.FileDescriptor - -var file_register_proto_rawDesc = []byte{ - 0x0a, 0x0e, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x12, 0x04, 0x61, 0x75, 0x74, 0x68, 0x1a, 0x09, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x22, 0x77, 0x0a, 0x12, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x44, 0x65, 0x66, - 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x71, 0x12, 0x2e, 0x0a, 0x07, 0x41, 0x63, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x14, 0xca, 0xbb, 0x18, 0x07, 0x61, 0x63, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0xda, 0xbb, 0x18, 0x05, 0x24, 0x21, 0x3d, 0x27, 0x27, 0x52, 0x07, - 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x31, 0x0a, 0x08, 0x50, 0x61, 0x73, 0x73, 0x77, - 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x15, 0xca, 0xbb, 0x18, 0x08, 0x70, - 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0xda, 0xbb, 0x18, 0x05, 0x24, 0x21, 0x3d, 0x27, 0x27, - 0x52, 0x08, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x15, 0x0a, 0x13, 0x52, 0x65, - 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x73, - 0x70, 0x32, 0x75, 0x0a, 0x0f, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, - 0x76, 0x69, 0x63, 0x65, 0x12, 0x62, 0x0a, 0x0f, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, - 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x52, - 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, - 0x71, 0x1a, 0x19, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, - 0x72, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x73, 0x70, 0x22, 0x1a, 0xd2, 0xc1, - 0x18, 0x16, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, - 0x2f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x42, 0x2a, 0x5a, 0x28, 0x63, 0x6e, 0x2f, 0x6f, - 0x6e, 0x65, 0x61, 0x6f, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2d, 0x67, 0x6f, 0x2f, 0x62, 0x69, 0x7a, - 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x72, 0x65, 0x67, 0x69, - 0x73, 0x74, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_register_proto_rawDescOnce sync.Once - file_register_proto_rawDescData = file_register_proto_rawDesc -) - -func file_register_proto_rawDescGZIP() []byte { - file_register_proto_rawDescOnce.Do(func() { - file_register_proto_rawDescData = protoimpl.X.CompressGZIP(file_register_proto_rawDescData) - }) - return file_register_proto_rawDescData -} - -var file_register_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_register_proto_goTypes = []interface{}{ - (*RegisterDefaultReq)(nil), // 0: auth.RegisterDefaultReq - (*RegisterDefaultResp)(nil), // 1: auth.RegisterDefaultResp -} -var file_register_proto_depIdxs = []int32{ - 0, // 0: auth.RegisterService.RegisterDefault:input_type -> auth.RegisterDefaultReq - 1, // 1: auth.RegisterService.RegisterDefault:output_type -> auth.RegisterDefaultResp - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] 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 -} - -func init() { file_register_proto_init() } -func file_register_proto_init() { - if File_register_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_register_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*RegisterDefaultReq); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_register_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*RegisterDefaultResp); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_register_proto_rawDesc, - NumEnums: 0, - NumMessages: 2, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_register_proto_goTypes, - DependencyIndexes: file_register_proto_depIdxs, - MessageInfos: file_register_proto_msgTypes, - }.Build() - File_register_proto = out.File - file_register_proto_rawDesc = nil - file_register_proto_goTypes = nil - file_register_proto_depIdxs = nil -} diff --git a/code/base-project/base-go-v3/biz/model/money_category/money_category.pb.go b/code/base-project/base-go-v3/biz/model/money_category/money_category.pb.go new file mode 100644 index 00000000..0a73a237 --- /dev/null +++ b/code/base-project/base-go-v3/biz/model/money_category/money_category.pb.go @@ -0,0 +1,316 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v4.25.3 +// source: money_category.proto + +package money_category + +import ( + _ "cn/oneao/base-go/biz/model/api" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type QueryUserMoneyCategoryReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *QueryUserMoneyCategoryReq) Reset() { + *x = QueryUserMoneyCategoryReq{} + if protoimpl.UnsafeEnabled { + mi := &file_money_category_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *QueryUserMoneyCategoryReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*QueryUserMoneyCategoryReq) ProtoMessage() {} + +func (x *QueryUserMoneyCategoryReq) ProtoReflect() protoreflect.Message { + mi := &file_money_category_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use QueryUserMoneyCategoryReq.ProtoReflect.Descriptor instead. +func (*QueryUserMoneyCategoryReq) Descriptor() ([]byte, []int) { + return file_money_category_proto_rawDescGZIP(), []int{0} +} + +type UserMoneyCategory struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" form:"id" json:"id" query:"id"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" form:"name" json:"name" query:"name"` + Icon string `protobuf:"bytes,3,opt,name=icon,proto3" form:"icon" json:"icon" query:"icon"` + Type int32 `protobuf:"varint,4,opt,name=type,proto3" form:"type" json:"type" query:"type"` + SortNumber int32 `protobuf:"varint,5,opt,name=sort_number,json=sortNumber,proto3" form:"sort_number" json:"sort_number" query:"sort_number"` +} + +func (x *UserMoneyCategory) Reset() { + *x = UserMoneyCategory{} + if protoimpl.UnsafeEnabled { + mi := &file_money_category_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UserMoneyCategory) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UserMoneyCategory) ProtoMessage() {} + +func (x *UserMoneyCategory) ProtoReflect() protoreflect.Message { + mi := &file_money_category_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UserMoneyCategory.ProtoReflect.Descriptor instead. +func (*UserMoneyCategory) Descriptor() ([]byte, []int) { + return file_money_category_proto_rawDescGZIP(), []int{1} +} + +func (x *UserMoneyCategory) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *UserMoneyCategory) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *UserMoneyCategory) GetIcon() string { + if x != nil { + return x.Icon + } + return "" +} + +func (x *UserMoneyCategory) GetType() int32 { + if x != nil { + return x.Type + } + return 0 +} + +func (x *UserMoneyCategory) GetSortNumber() int32 { + if x != nil { + return x.SortNumber + } + return 0 +} + +type QueryUserMoneyCategoryResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Categories []*UserMoneyCategory `protobuf:"bytes,1,rep,name=categories,proto3" form:"categories" json:"categories" query:"categories"` +} + +func (x *QueryUserMoneyCategoryResp) Reset() { + *x = QueryUserMoneyCategoryResp{} + if protoimpl.UnsafeEnabled { + mi := &file_money_category_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *QueryUserMoneyCategoryResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*QueryUserMoneyCategoryResp) ProtoMessage() {} + +func (x *QueryUserMoneyCategoryResp) ProtoReflect() protoreflect.Message { + mi := &file_money_category_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use QueryUserMoneyCategoryResp.ProtoReflect.Descriptor instead. +func (*QueryUserMoneyCategoryResp) Descriptor() ([]byte, []int) { + return file_money_category_proto_rawDescGZIP(), []int{2} +} + +func (x *QueryUserMoneyCategoryResp) GetCategories() []*UserMoneyCategory { + if x != nil { + return x.Categories + } + return nil +} + +var File_money_category_proto protoreflect.FileDescriptor + +var file_money_category_proto_rawDesc = []byte{ + 0x0a, 0x14, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x5f, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x5f, 0x63, 0x61, + 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x1a, 0x09, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x22, 0x1b, 0x0a, 0x19, 0x51, 0x75, 0x65, 0x72, 0x79, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x6f, + 0x6e, 0x65, 0x79, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x22, 0x80, + 0x01, 0x0a, 0x11, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x43, 0x61, 0x74, 0x65, + 0x67, 0x6f, 0x72, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x69, 0x63, 0x6f, 0x6e, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x69, 0x63, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, + 0x74, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, + 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x6f, 0x72, 0x74, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x73, 0x6f, 0x72, 0x74, 0x4e, 0x75, 0x6d, 0x62, 0x65, + 0x72, 0x22, 0x5f, 0x0a, 0x1a, 0x51, 0x75, 0x65, 0x72, 0x79, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x6f, + 0x6e, 0x65, 0x79, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x12, + 0x41, 0x0a, 0x0a, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x5f, 0x63, 0x61, 0x74, 0x65, + 0x67, 0x6f, 0x72, 0x79, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x43, 0x61, + 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x52, 0x0a, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, + 0x65, 0x73, 0x32, 0x9d, 0x01, 0x0a, 0x14, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x43, 0x61, 0x74, 0x65, + 0x67, 0x6f, 0x72, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x84, 0x01, 0x0a, 0x16, + 0x51, 0x75, 0x65, 0x72, 0x79, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x43, 0x61, + 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x12, 0x29, 0x2e, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x5f, 0x63, + 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x55, 0x73, 0x65, + 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x52, 0x65, + 0x71, 0x1a, 0x2a, 0x2e, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x5f, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, + 0x72, 0x79, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x6f, 0x6e, 0x65, + 0x79, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x22, 0x13, 0xca, + 0xc1, 0x18, 0x0f, 0x2f, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x2f, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, + 0x72, 0x79, 0x42, 0x2b, 0x5a, 0x29, 0x63, 0x6e, 0x2f, 0x6f, 0x6e, 0x65, 0x61, 0x6f, 0x2f, 0x62, + 0x61, 0x73, 0x65, 0x2d, 0x67, 0x6f, 0x2f, 0x62, 0x69, 0x7a, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, + 0x2f, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x5f, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_money_category_proto_rawDescOnce sync.Once + file_money_category_proto_rawDescData = file_money_category_proto_rawDesc +) + +func file_money_category_proto_rawDescGZIP() []byte { + file_money_category_proto_rawDescOnce.Do(func() { + file_money_category_proto_rawDescData = protoimpl.X.CompressGZIP(file_money_category_proto_rawDescData) + }) + return file_money_category_proto_rawDescData +} + +var file_money_category_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_money_category_proto_goTypes = []interface{}{ + (*QueryUserMoneyCategoryReq)(nil), // 0: money_category.QueryUserMoneyCategoryReq + (*UserMoneyCategory)(nil), // 1: money_category.UserMoneyCategory + (*QueryUserMoneyCategoryResp)(nil), // 2: money_category.QueryUserMoneyCategoryResp +} +var file_money_category_proto_depIdxs = []int32{ + 1, // 0: money_category.QueryUserMoneyCategoryResp.categories:type_name -> money_category.UserMoneyCategory + 0, // 1: money_category.MoneyCategoryService.QueryUserMoneyCategory:input_type -> money_category.QueryUserMoneyCategoryReq + 2, // 2: money_category.MoneyCategoryService.QueryUserMoneyCategory:output_type -> money_category.QueryUserMoneyCategoryResp + 2, // [2:3] is the sub-list for method output_type + 1, // [1:2] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_money_category_proto_init() } +func file_money_category_proto_init() { + if File_money_category_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_money_category_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*QueryUserMoneyCategoryReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_money_category_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UserMoneyCategory); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_money_category_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*QueryUserMoneyCategoryResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_money_category_proto_rawDesc, + NumEnums: 0, + NumMessages: 3, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_money_category_proto_goTypes, + DependencyIndexes: file_money_category_proto_depIdxs, + MessageInfos: file_money_category_proto_msgTypes, + }.Build() + File_money_category_proto = out.File + file_money_category_proto_rawDesc = nil + file_money_category_proto_goTypes = nil + file_money_category_proto_depIdxs = nil +} diff --git a/code/base-project/base-go-v3/biz/router/register/register.go b/code/base-project/base-go-v3/biz/router/auth/auth.go similarity index 63% rename from code/base-project/base-go-v3/biz/router/register/register.go rename to code/base-project/base-go-v3/biz/router/auth/auth.go index 95c2f421..9b2f69e6 100644 --- a/code/base-project/base-go-v3/biz/router/register/register.go +++ b/code/base-project/base-go-v3/biz/router/auth/auth.go @@ -1,9 +1,9 @@ // Code generated by hertz generator. DO NOT EDIT. -package register +package auth import ( - register "cn/oneao/base-go/biz/handler/register" + auth "cn/oneao/base-go/biz/handler/auth" "github.com/cloudwego/hertz/pkg/app/server" ) @@ -19,9 +19,14 @@ func Register(r *server.Hertz) { root := r.Group("/", rootMw()...) { _auth := root.Group("/auth", _authMw()...) + _auth.POST("/refreshToken", append(_refreshaccesstokenMw(), auth.RefreshAccessToken)...) + { + _login := _auth.Group("/login", _loginMw()...) + _login.POST("/default", append(_logindefaultMw(), auth.LoginDefault)...) + } { _register := _auth.Group("/register", _registerMw()...) - _register.POST("/default", append(_registerdefaultMw(), register.RegisterDefault)...) + _register.POST("/default", append(_registerdefaultMw(), auth.RegisterDefault)...) } } } diff --git a/code/base-project/base-go-v3/biz/router/login/middleware.go b/code/base-project/base-go-v3/biz/router/auth/middleware.go similarity index 60% rename from code/base-project/base-go-v3/biz/router/login/middleware.go rename to code/base-project/base-go-v3/biz/router/auth/middleware.go index 22d105ca..7a48efbb 100644 --- a/code/base-project/base-go-v3/biz/router/login/middleware.go +++ b/code/base-project/base-go-v3/biz/router/auth/middleware.go @@ -1,6 +1,6 @@ // Code generated by hertz generator. -package login +package auth import ( "github.com/cloudwego/hertz/pkg/app" @@ -25,3 +25,18 @@ func _logindefaultMw() []app.HandlerFunc { // your code... return nil } + +func _registerMw() []app.HandlerFunc { + // your code... + return nil +} + +func _registerdefaultMw() []app.HandlerFunc { + // your code... + return nil +} + +func _refreshaccesstokenMw() []app.HandlerFunc { + // your code... + return nil +} diff --git a/code/base-project/base-go-v3/biz/router/middleware/auth.go b/code/base-project/base-go-v3/biz/router/middleware/auth.go new file mode 100644 index 00000000..119bbd6c --- /dev/null +++ b/code/base-project/base-go-v3/biz/router/middleware/auth.go @@ -0,0 +1,67 @@ +package middleware + +import ( + "cn/oneao/base-go/utils/jwtx" + "cn/oneao/base-go/utils/pathx" + "cn/oneao/base-go/utils/response" + "context" + "github.com/cloudwego/hertz/pkg/app" +) + +// 私有 key,防止冲突 +type ctxKeyUserID struct{} + +// Auth 中间件,直接在中间件里过滤白名单路径 +func Auth() app.HandlerFunc { + // 白名单路径,直接写死 + whitelistPaths := []string{ + "/auth/login", + "/auth/register", + "/auth/refreshToken", + } + + return func(ctx context.Context, c *app.RequestContext) { + path := string(c.Request.URI().Path()) + + // 使用工具函数判断是否在白名单 + if pathx.MatchPath(path, whitelistPaths) { + c.Next(ctx) + return + } + + // 获取 token + token := string(c.GetHeader("token")) + if token == "" { + response.Fail(c).Code(response.HttpCode.Unauthorized).Send() + c.Abort() + return + } + + verifyToken := jwtx.VerifyToken(token) + + if verifyToken.IsValid { + // 设置 userID 到 context + ctx = setUserID(ctx, verifyToken.Claims.UserID) + c.Next(ctx) + return + } + + // token 无效 + response.Fail(c).Code(response.HttpCode.RefreshToken).Send() + c.Abort() + } +} + +// GetUserID 从 context 中获取 user_id +func GetUserID(ctx context.Context) int64 { + userID, ok := ctx.Value(ctxKeyUserID{}).(int64) + if !ok { + return 0 // 或者返回 error,根据业务需求 + } + return userID +} + +// 内部中间件设置 user_id +func setUserID(ctx context.Context, userID int64) context.Context { + return context.WithValue(ctx, ctxKeyUserID{}, userID) +} diff --git a/code/base-project/base-go-v3/biz/router/middleware/error.go b/code/base-project/base-go-v3/biz/router/middleware/error.go new file mode 100644 index 00000000..65671be1 --- /dev/null +++ b/code/base-project/base-go-v3/biz/router/middleware/error.go @@ -0,0 +1,100 @@ +package middleware + +import ( + "cn/oneao/base-go/logx" + "cn/oneao/base-go/utils/response" + "context" + "fmt" + "go.uber.org/zap" + "runtime/debug" + "strings" + + "github.com/cloudwego/hertz/pkg/app" + "github.com/pkg/errors" +) + +// ErrorInfo 封装错误信息和调用栈 +type ErrorInfo struct { + Message string // 错误信息 + FuncName string // 出错函数 + File string // 文件路径 + Line string // 行号 + Stack string // 完整堆栈信息 +} + +// Error 中间件 +func Error() app.HandlerFunc { + return func(ctx context.Context, c *app.RequestContext) { + c.Next(ctx) + + if e := c.Errors.Last(); e != nil && e.Err != nil { + info := ParseError(e.Err) + + logx.CtxError(ctx, "系统异常", + zap.String("Message", info.Message), + zap.String("File", info.File), + zap.String("Line", info.Line), + zap.String("Func", info.FuncName), + zap.String("Stack", info.Stack), + ) + + // 返回给前端 + response.Fail(c).Message("系统异常,请联系管理员!").Send() + } + } +} + +// ParseError 解析 error 为 ErrorInfo +func ParseError(err error) *ErrorInfo { + if err == nil { + return nil + } + + info := &ErrorInfo{ + Message: err.Error(), + Stack: string(debug.Stack()), // 默认 runtime stack + } + + // 尝试解析 pkg/errors stack + type stackTracer interface { + StackTrace() errors.StackTrace + } + + if errWithStack, ok := err.(stackTracer); ok { + st := errWithStack.StackTrace() + var funcName, fileLine string + for _, f := range st { + line := fmt.Sprintf("%+v", f) + // 取 biz/ 目录下第一个函数作为业务函数 + if strings.Contains(line, "/biz/") { + parts := strings.Split(line, "\n") + if len(parts) >= 2 { + funcName = strings.TrimSpace(parts[0]) + fileLine = strings.TrimSpace(parts[1]) + } else { + funcName = strings.TrimSpace(line) + fileLine = strings.TrimSpace(line) + } + break + } + } + info.FuncName = funcName + // 分离文件和行号 + if idx := strings.LastIndex(fileLine, ":"); idx > 0 { + info.File = fileLine[:idx] + info.Line = fileLine[idx+1:] + } else { + info.File = fileLine + info.Line = "" + } + + // 完整堆栈 + stackStr := "" + for _, f := range st { + stackStr += fmt.Sprintf("%+v\n", f) + } + info.Stack = stackStr + } + + return info +} diff --git a/code/base-project/base-go-v3/middleware/jwt.go b/code/base-project/base-go-v3/biz/router/middleware/jwt.go similarity index 100% rename from code/base-project/base-go-v3/middleware/jwt.go rename to code/base-project/base-go-v3/biz/router/middleware/jwt.go diff --git a/code/base-project/base-go-v3/middleware/log.go b/code/base-project/base-go-v3/biz/router/middleware/log.go similarity index 100% rename from code/base-project/base-go-v3/middleware/log.go rename to code/base-project/base-go-v3/biz/router/middleware/log.go diff --git a/code/base-project/base-go-v3/biz/router/register/middleware.go b/code/base-project/base-go-v3/biz/router/money_category/middleware.go similarity index 62% rename from code/base-project/base-go-v3/biz/router/register/middleware.go rename to code/base-project/base-go-v3/biz/router/money_category/middleware.go index 7891cd8b..f4a92cf0 100644 --- a/code/base-project/base-go-v3/biz/router/register/middleware.go +++ b/code/base-project/base-go-v3/biz/router/money_category/middleware.go @@ -1,6 +1,6 @@ // Code generated by hertz generator. -package register +package money_category import ( "github.com/cloudwego/hertz/pkg/app" @@ -11,17 +11,17 @@ func rootMw() []app.HandlerFunc { return nil } -func _authMw() []app.HandlerFunc { +func _moneyMw() []app.HandlerFunc { // your code... return nil } -func _registerMw() []app.HandlerFunc { +func _categoryMw() []app.HandlerFunc { // your code... return nil } -func _registerdefaultMw() []app.HandlerFunc { +func _queryusermoneycategoryMw() []app.HandlerFunc { // your code... return nil } diff --git a/code/base-project/base-go-v3/biz/router/login/login.go b/code/base-project/base-go-v3/biz/router/money_category/money_category.go similarity index 68% rename from code/base-project/base-go-v3/biz/router/login/login.go rename to code/base-project/base-go-v3/biz/router/money_category/money_category.go index 2bc01680..60accc04 100644 --- a/code/base-project/base-go-v3/biz/router/login/login.go +++ b/code/base-project/base-go-v3/biz/router/money_category/money_category.go @@ -1,9 +1,9 @@ // Code generated by hertz generator. DO NOT EDIT. -package login +package money_category import ( - login "cn/oneao/base-go/biz/handler/login" + money_category "cn/oneao/base-go/biz/handler/money_category" "github.com/cloudwego/hertz/pkg/app/server" ) @@ -18,10 +18,7 @@ func Register(r *server.Hertz) { root := r.Group("/", rootMw()...) { - _auth := root.Group("/auth", _authMw()...) - { - _login := _auth.Group("/login", _loginMw()...) - _login.POST("/default", append(_logindefaultMw(), login.LoginDefault)...) - } + _money := root.Group("/money", _moneyMw()...) + _money.GET("/category", append(_queryusermoneycategoryMw(), money_category.QueryUserMoneyCategory)...) } } diff --git a/code/base-project/base-go-v3/biz/router/register.go b/code/base-project/base-go-v3/biz/router/register.go index ecbab561..d67e9e4e 100644 --- a/code/base-project/base-go-v3/biz/router/register.go +++ b/code/base-project/base-go-v3/biz/router/register.go @@ -3,15 +3,15 @@ package router import ( - login "cn/oneao/base-go/biz/router/login" - register "cn/oneao/base-go/biz/router/register" + auth "cn/oneao/base-go/biz/router/auth" + money_category "cn/oneao/base-go/biz/router/money_category" "github.com/cloudwego/hertz/pkg/app/server" ) // GeneratedRegister registers routers generated by IDL. func GeneratedRegister(r *server.Hertz) { //INSERT_POINT: DO NOT DELETE THIS LINE! - register.Register(r) + money_category.Register(r) - login.Register(r) + auth.Register(r) } diff --git a/code/base-project/base-go-v3/conf/conf.go b/code/base-project/base-go-v3/conf/conf.go new file mode 100644 index 00000000..5cb2992c --- /dev/null +++ b/code/base-project/base-go-v3/conf/conf.go @@ -0,0 +1,95 @@ +package conf + +import ( + "github.com/spf13/viper" + "os" + "path/filepath" + "sync" + "time" +) + +var ( + conf *Config + once sync.Once +) + +type Config struct { + Env string + + Server ServerConfig `mapstructure:"server" yaml:"server"` + JWT JwtConfig `mapstructure:"jwt" yaml:"jwt"` + Snowflake SnowflakeConfig `mapstructure:"snowflake" yaml:"snowflake"` + Pgsql PgsqlConfig `mapstructure:"pgsql" yaml:"pgsql"` + Log LogConfig `mapstructure:"log" yaml:"log"` +} + +type ServerConfig struct { + Port string `mapstructure:"port" yaml:"port"` + BaseUrl string `mapstructure:"base_url" yaml:"base_url"` // 下划线 +} + +type JwtConfig struct { + Secret string `mapstructure:"secret" yaml:"secret"` + AccessExpiry time.Duration `mapstructure:"access_expiry" yaml:"access_expiry"` + RefreshExpiry time.Duration `mapstructure:"refresh_expiry" yaml:"refresh_expiry"` +} + +type SnowflakeConfig struct { + DatacenterID uint16 `mapstructure:"datacenter_id" yaml:"datacenter_id"` + WorkerID uint16 `mapstructure:"worker_id" yaml:"worker_id"` +} + +type PgsqlConfig struct { + Host string `mapstructure:"host" yaml:"host"` + Port int `mapstructure:"port" yaml:"port"` + User string `mapstructure:"user" yaml:"user"` + Password string `mapstructure:"password" yaml:"password"` + Dbname string `mapstructure:"dbname" yaml:"dbname"` + SllMode bool `mapstructure:"sll_mode" yaml:"sll_mode"` + TimeZone string `mapstructure:"timezone" yaml:"timezone"` + MaxOpenConns int32 `mapstructure:"max_open_conns" yaml:"max_open_conns"` + MaxIdleConns int32 `mapstructure:"max_idle_conns" yaml:"max_idle_conns"` + ConnMaxLifetime time.Duration `mapstructure:"conn_max_lifetime" yaml:"conn_max_lifetime"` +} + +type LogConfig struct { + Level string `mapstructure:"level" yaml:"level"` + Dir string `mapstructure:"dir" yaml:"dir"` + MaxSize int `mapstructure:"max_size" yaml:"max_size"` + MaxBackups int `mapstructure:"max_backups" yaml:"max_backups"` + MaxAge int `mapstructure:"max_age" yaml:"max_age"` + Compress bool `mapstructure:"compress" yaml:"compress"` +} + +func GetConf() *Config { + once.Do(initConf) + return conf +} + +func initConf() { + prefix := "conf" + confFileRelPath := filepath.Join(prefix, filepath.Join(GetEnv(), "conf.yaml")) + + v := viper.New() + v.SetConfigFile(confFileRelPath) + v.SetConfigType("yaml") + + if err := v.ReadInConfig(); err != nil { + panic(err) + } + + conf = new(Config) + if err := v.Unmarshal(conf); err != nil { + panic(err) + } + + conf.Env = GetEnv() +} + +func GetEnv() string { + e := os.Getenv("GO_ENV") + if len(e) == 0 { + return "dev" + } + return e +} diff --git a/code/base-project/base-go-v3/conf/dev/conf.yaml b/code/base-project/base-go-v3/conf/dev/conf.yaml new file mode 100644 index 00000000..b193b217 --- /dev/null +++ b/code/base-project/base-go-v3/conf/dev/conf.yaml @@ -0,0 +1,32 @@ +server: + port: 8086 + base_url: /app + +jwt: + secret: 3Bde3BGEbYqtqyEUzW3ry8jKFcaPH17fRmTmqE7MDr05Lwj95uruRKrrkb44TJ4s + access_expiry: 720h + refresh_expiry: 720h + +snowflake: + datacenter_id: 1 + worker_id: 1 + +pgsql: + host: 117.72.182.135 + port: 5432 + user: postgres + password: zhang520.. + dbname: base + timezone: Asia/Shanghai + max_open_conns: 10 + max_idle_conns: 5 + conn_max_lifetime: 30m + sll_mode: false + +log: + level: "debug" + dir: "./logs" + max_size: 10 + max_backups: 30 + max_age: 7 + compress: true \ No newline at end of file diff --git a/code/base-project/base-go-v3/config/app.go b/code/base-project/base-go-v3/config/app.go deleted file mode 100644 index d6b6f3e2..00000000 --- a/code/base-project/base-go-v3/config/app.go +++ /dev/null @@ -1,43 +0,0 @@ -package config - -import ( - "time" -) - -type appConfig struct { - Server serverConfig - JWT jwtConfig - Snowflake snowflakeConfig -} - -type serverConfig struct { - Port string - BaseUrl string -} - -type jwtConfig struct { - Secret string - AccessExpiry time.Duration - RefreshExpiry time.Duration -} - -type snowflakeConfig struct { - DatacenterID uint16 - WorkerID uint16 -} - -var App = &appConfig{ - Server: serverConfig{ - Port: ":8086", - BaseUrl: "/app", - }, - JWT: jwtConfig{ - Secret: "3Bde3BGEbYqtqyEUzW3ry8jKFcaPH17fRmTmqE7MDr05Lwj95uruRKrrkb44TJ4s", - AccessExpiry: 30 * time.Minute, - RefreshExpiry: 30 * 24 * time.Hour, - }, - Snowflake: snowflakeConfig{ - DatacenterID: 1, - WorkerID: 1, - }, -} diff --git a/code/base-project/base-go-v3/config/database.go b/code/base-project/base-go-v3/config/database.go deleted file mode 100644 index 894f06bf..00000000 --- a/code/base-project/base-go-v3/config/database.go +++ /dev/null @@ -1,32 +0,0 @@ -package config - -import ( - "time" -) - -type dbConfig struct { - Host string - Port int - User string - Password string - Dbname string - SllMode bool - TimeZone string - MaxOpenConns int - MaxIdleConns int - ConnMaxLifetime time.Duration -} - -// Db 默认值 -var Db = &dbConfig{ - Host: "117.72.182.135", - Port: 5432, - User: "postgres", - Password: "zhang520..", - Dbname: "base", - SllMode: false, - TimeZone: "Asia/Shanghai", - MaxOpenConns: 10, - MaxIdleConns: 5, - ConnMaxLifetime: 30 * time.Minute, -} diff --git a/code/base-project/base-go-v3/db/index.go b/code/base-project/base-go-v3/db/index.go index a8863d1e..c8d4d868 100644 --- a/code/base-project/base-go-v3/db/index.go +++ b/code/base-project/base-go-v3/db/index.go @@ -2,7 +2,7 @@ package db import ( - "cn/oneao/base-go/config" + "cn/oneao/base-go/conf" sqlcg "cn/oneao/base-go/db/sqlc" "context" "fmt" @@ -11,19 +11,18 @@ import ( ) var ( - DB *pgxpool.Pool - DBClient *sqlcg.Queries + DB *pgxpool.Pool + Queries *sqlcg.Queries ) -func InitDB() error { - cfg := config.Db +func InitDB() { + cfg := conf.GetConf().Pgsql sslMode := "disable" if cfg.SllMode { sslMode = "require" } - // 构建 DSN dsn := fmt.Sprintf( "postgres://%s:%s@%s:%d/%s?sslmode=%s&TimeZone=%s", cfg.User, cfg.Password, cfg.Host, cfg.Port, cfg.Dbname, sslMode, cfg.TimeZone, @@ -32,25 +31,37 @@ func InitDB() error { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - pool, err := pgxpool.New(ctx, dsn) + // 使用可修改配置 + cfgPool, err := pgxpool.ParseConfig(dsn) if err != nil { - return fmt.Errorf("unable to connect to database: %w", err) + panic(err) + } + + // 给连接池参数设置默认值 + if cfg.MaxOpenConns <= 0 { + cfg.MaxOpenConns = 10 + } + if cfg.MaxIdleConns <= 0 { + cfg.MaxIdleConns = 5 + } + if cfg.ConnMaxLifetime <= 0 { + cfg.ConnMaxLifetime = 30 * time.Minute + } + + cfgPool.MaxConns = cfg.MaxOpenConns + cfgPool.MinConns = cfg.MaxIdleConns + cfgPool.MaxConnLifetime = cfg.ConnMaxLifetime + + pool, err := pgxpool.NewWithConfig(ctx, cfgPool) + if err != nil { + panic(err) } // 测试连接 if err := pool.Ping(ctx); err != nil { - return fmt.Errorf("ping database failed: %w", err) + panic(err) } DB = pool - - // 初始化 sqlc Queries,全局可用 - DBClient = sqlcg.New(DB) - - // 可选:设置连接池参数 - pool.Config().MaxConns = int32(cfg.MaxOpenConns) - pool.Config().MinConns = int32(cfg.MaxIdleConns) - pool.Config().MaxConnLifetime = cfg.ConnMaxLifetime - - return nil + Queries = sqlcg.New(DB) } diff --git a/code/base-project/base-go-v3/db/queries/money_record.sql b/code/base-project/base-go-v3/db/queries/money_record.sql new file mode 100644 index 00000000..e69de29b diff --git a/code/base-project/base-go-v3/db/queries/money_sys_category.sql b/code/base-project/base-go-v3/db/queries/money_sys_category.sql new file mode 100644 index 00000000..51a3ba87 --- /dev/null +++ b/code/base-project/base-go-v3/db/queries/money_sys_category.sql @@ -0,0 +1,2 @@ +-- name: ListMoneySysCategory :many +SELECT * FROM money_sys_category; diff --git a/code/base-project/base-go-v3/db/queries/money_user_category.sql b/code/base-project/base-go-v3/db/queries/money_user_category.sql new file mode 100644 index 00000000..582da908 --- /dev/null +++ b/code/base-project/base-go-v3/db/queries/money_user_category.sql @@ -0,0 +1,8 @@ +-- name: BatchInsertMoneyUserCategories :copyfrom +INSERT INTO money_user_category (id, user_id, name, icon, type, sort_number) +VALUES ($1, $2, $3, $4, $5, $6); + +-- name: FindUserMoneyCategoriesByUserID :many +SELECT * +FROM money_user_category +WHERE user_id = $1; diff --git a/code/base-project/base-go-v3/db/queries/user_info.sql b/code/base-project/base-go-v3/db/queries/user_info.sql index 7af130d0..97b60413 100644 --- a/code/base-project/base-go-v3/db/queries/user_info.sql +++ b/code/base-project/base-go-v3/db/queries/user_info.sql @@ -1,23 +1,30 @@ --- name: CreateUser :execrows -- 插入用户并返回刚创建的记录 +-- name: InsertUser :execrows INSERT INTO user_info (id, account, password) VALUES ($1, $2, $3); --- name: GetUserById :one -- 根据 ID 查询单条用户记录 +-- name: GetUserById :one SELECT * FROM user_info WHERE id = $1; --- name: GetUserByAccountAndPassword :one +-- 根据账号查询单条用户记录 +-- name: GetUserByAccount :one +SELECT * +FROM user_info +WHERE account = $1; + -- 根据账号和密码查询单条用户记录(登录用) +-- name: GetUserForLogin :one SELECT * FROM user_info WHERE account = $1 AND password = $2; +-- 更新用户最后登录时间,并返回更新后的记录 -- name: UpdateUserLoginLastTime :execrows --- 更新用户最后登录时间,并返回影响的行数 UPDATE user_info SET last_login_time = now() WHERE id = $1; + diff --git a/code/base-project/base-go-v3/db/schema.sql b/code/base-project/base-go-v3/db/schema.sql index 16ae1431..fcfe1aba 100644 --- a/code/base-project/base-go-v3/db/schema.sql +++ b/code/base-project/base-go-v3/db/schema.sql @@ -26,7 +26,7 @@ CREATE TABLE money_sys_category( id BIGINT PRIMARY KEY , name VARCHAR(255) NOT NULL , icon VARCHAR(255) NOT NULL, - type SMALLINT DEFAULT 0, + type INT DEFAULT 0, sort_number INT DEFAULT 0, create_time timestamp DEFAULT CURRENT_TIMESTAMP ); @@ -36,7 +36,7 @@ CREATE TABLE money_user_category( user_id BIGINT NOT NULL, name VARCHAR(255) NOT NULL , icon VARCHAR(255) NOT NULL, - type SMALLINT DEFAULT 0, + type INT DEFAULT 0, sort_number INT DEFAULT 0, create_time timestamp DEFAULT CURRENT_TIMESTAMP ) diff --git a/code/base-project/base-go-v3/db/sqlc/copyfrom.go b/code/base-project/base-go-v3/db/sqlc/copyfrom.go new file mode 100644 index 00000000..5be28489 --- /dev/null +++ b/code/base-project/base-go-v3/db/sqlc/copyfrom.go @@ -0,0 +1,47 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: copyfrom.go + +package dbtype + +import ( + "context" +) + +// iteratorForBatchInsertMoneyUserCategories implements pgx.CopyFromSource. +type iteratorForBatchInsertMoneyUserCategories struct { + rows []BatchInsertMoneyUserCategoriesParams + skippedFirstNextCall bool +} + +func (r *iteratorForBatchInsertMoneyUserCategories) Next() bool { + if len(r.rows) == 0 { + return false + } + if !r.skippedFirstNextCall { + r.skippedFirstNextCall = true + return true + } + r.rows = r.rows[1:] + return len(r.rows) > 0 +} + +func (r iteratorForBatchInsertMoneyUserCategories) Values() ([]interface{}, error) { + return []interface{}{ + r.rows[0].ID, + r.rows[0].UserID, + r.rows[0].Name, + r.rows[0].Icon, + r.rows[0].Type, + r.rows[0].SortNumber, + }, nil +} + +func (r iteratorForBatchInsertMoneyUserCategories) Err() error { + return nil +} + +func (q *Queries) BatchInsertMoneyUserCategories(ctx context.Context, arg []BatchInsertMoneyUserCategoriesParams) (int64, error) { + return q.db.CopyFrom(ctx, []string{"money_user_category"}, []string{"id", "user_id", "name", "icon", "type", "sort_number"}, &iteratorForBatchInsertMoneyUserCategories{rows: arg}) +} diff --git a/code/base-project/base-go-v3/db/sqlc/db.go b/code/base-project/base-go-v3/db/sqlc/db.go index 4f1cfa52..23ee0649 100644 --- a/code/base-project/base-go-v3/db/sqlc/db.go +++ b/code/base-project/base-go-v3/db/sqlc/db.go @@ -2,7 +2,7 @@ // versions: // sqlc v1.30.0 -package sqlcg +package dbtype import ( "context" @@ -15,6 +15,7 @@ type DBTX interface { Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error) Query(context.Context, string, ...interface{}) (pgx.Rows, error) QueryRow(context.Context, string, ...interface{}) pgx.Row + CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error) } func New(db DBTX) *Queries { diff --git a/code/base-project/base-go-v3/db/sqlc/models.go b/code/base-project/base-go-v3/db/sqlc/models.go index b4346c26..fa9d1acb 100644 --- a/code/base-project/base-go-v3/db/sqlc/models.go +++ b/code/base-project/base-go-v3/db/sqlc/models.go @@ -2,7 +2,7 @@ // versions: // sqlc v1.30.0 -package sqlcg +package dbtype import ( "github.com/jackc/pgx/v5/pgtype" @@ -23,7 +23,7 @@ type MoneySysCategory struct { ID int64 Name string Icon string - Type pgtype.Int2 + Type pgtype.Int4 SortNumber pgtype.Int4 CreateTime pgtype.Timestamp } @@ -33,7 +33,7 @@ type MoneyUserCategory struct { UserID int64 Name string Icon string - Type pgtype.Int2 + Type pgtype.Int4 SortNumber pgtype.Int4 CreateTime pgtype.Timestamp } diff --git a/code/base-project/base-go-v3/db/sqlc/money_sys_category.sql.go b/code/base-project/base-go-v3/db/sqlc/money_sys_category.sql.go new file mode 100644 index 00000000..693242f1 --- /dev/null +++ b/code/base-project/base-go-v3/db/sqlc/money_sys_category.sql.go @@ -0,0 +1,41 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: money_sys_category.sql + +package dbtype + +import ( + "context" +) + +const listMoneySysCategory = `-- name: ListMoneySysCategory :many +SELECT id, name, icon, type, sort_number, create_time FROM money_sys_category +` + +func (q *Queries) ListMoneySysCategory(ctx context.Context) ([]MoneySysCategory, error) { + rows, err := q.db.Query(ctx, listMoneySysCategory) + if err != nil { + return nil, err + } + defer rows.Close() + var items []MoneySysCategory + for rows.Next() { + var i MoneySysCategory + if err := rows.Scan( + &i.ID, + &i.Name, + &i.Icon, + &i.Type, + &i.SortNumber, + &i.CreateTime, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} diff --git a/code/base-project/base-go-v3/db/sqlc/money_user_category.sql.go b/code/base-project/base-go-v3/db/sqlc/money_user_category.sql.go new file mode 100644 index 00000000..06d9a362 --- /dev/null +++ b/code/base-project/base-go-v3/db/sqlc/money_user_category.sql.go @@ -0,0 +1,55 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: money_user_category.sql + +package dbtype + +import ( + "context" + + "github.com/jackc/pgx/v5/pgtype" +) + +type BatchInsertMoneyUserCategoriesParams struct { + ID int64 + UserID int64 + Name string + Icon string + Type pgtype.Int4 + SortNumber pgtype.Int4 +} + +const findUserMoneyCategoriesByUserID = `-- name: FindUserMoneyCategoriesByUserID :many +SELECT id, user_id, name, icon, type, sort_number, create_time +FROM money_user_category +WHERE user_id = $1 +` + +func (q *Queries) FindUserMoneyCategoriesByUserID(ctx context.Context, userID int64) ([]MoneyUserCategory, error) { + rows, err := q.db.Query(ctx, findUserMoneyCategoriesByUserID, userID) + if err != nil { + return nil, err + } + defer rows.Close() + var items []MoneyUserCategory + for rows.Next() { + var i MoneyUserCategory + if err := rows.Scan( + &i.ID, + &i.UserID, + &i.Name, + &i.Icon, + &i.Type, + &i.SortNumber, + &i.CreateTime, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} diff --git a/code/base-project/base-go-v3/db/sqlc/user_info.sql.go b/code/base-project/base-go-v3/db/sqlc/user_info.sql.go index 0a7c3c51..af84da7e 100644 --- a/code/base-project/base-go-v3/db/sqlc/user_info.sql.go +++ b/code/base-project/base-go-v3/db/sqlc/user_info.sql.go @@ -3,47 +3,21 @@ // sqlc v1.30.0 // source: user_info.sql -package sqlcg +package dbtype import ( "context" ) -const createUser = `-- name: CreateUser :execrows -INSERT INTO user_info (id, account, password) -VALUES ($1, $2, $3) -` - -type CreateUserParams struct { - ID int64 - Account string - Password string -} - -// 插入用户并返回刚创建的记录 -func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (int64, error) { - result, err := q.db.Exec(ctx, createUser, arg.ID, arg.Account, arg.Password) - if err != nil { - return 0, err - } - return result.RowsAffected(), nil -} - -const getUserByAccountAndPassword = `-- name: GetUserByAccountAndPassword :one +const getUserByAccount = `-- name: GetUserByAccount :one SELECT id, seq_no, account, password, email, username, gender, create_time, update_time, last_login_time FROM user_info WHERE account = $1 - AND password = $2 ` -type GetUserByAccountAndPasswordParams struct { - Account string - Password string -} - -// 根据账号和密码查询单条用户记录(登录用) -func (q *Queries) GetUserByAccountAndPassword(ctx context.Context, arg GetUserByAccountAndPasswordParams) (UserInfo, error) { - row := q.db.QueryRow(ctx, getUserByAccountAndPassword, arg.Account, arg.Password) +// 根据账号查询单条用户记录 +func (q *Queries) GetUserByAccount(ctx context.Context, account string) (UserInfo, error) { + row := q.db.QueryRow(ctx, getUserByAccount, account) var i UserInfo err := row.Scan( &i.ID, @@ -85,13 +59,64 @@ func (q *Queries) GetUserById(ctx context.Context, id int64) (UserInfo, error) { return i, err } +const getUserForLogin = `-- name: GetUserForLogin :one +SELECT id, seq_no, account, password, email, username, gender, create_time, update_time, last_login_time +FROM user_info +WHERE account = $1 + AND password = $2 +` + +type GetUserForLoginParams struct { + Account string + Password string +} + +// 根据账号和密码查询单条用户记录(登录用) +func (q *Queries) GetUserForLogin(ctx context.Context, arg GetUserForLoginParams) (UserInfo, error) { + row := q.db.QueryRow(ctx, getUserForLogin, arg.Account, arg.Password) + var i UserInfo + err := row.Scan( + &i.ID, + &i.SeqNo, + &i.Account, + &i.Password, + &i.Email, + &i.Username, + &i.Gender, + &i.CreateTime, + &i.UpdateTime, + &i.LastLoginTime, + ) + return i, err +} + +const insertUser = `-- name: InsertUser :execrows +INSERT INTO user_info (id, account, password) +VALUES ($1, $2, $3) +` + +type InsertUserParams struct { + ID int64 + Account string + Password string +} + +// 插入用户并返回刚创建的记录 +func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) (int64, error) { + result, err := q.db.Exec(ctx, insertUser, arg.ID, arg.Account, arg.Password) + if err != nil { + return 0, err + } + return result.RowsAffected(), nil +} + const updateUserLoginLastTime = `-- name: UpdateUserLoginLastTime :execrows UPDATE user_info SET last_login_time = now() WHERE id = $1 ` -// 更新用户最后登录时间,并返回影响的行数 +// 更新用户最后登录时间,并返回更新后的记录 func (q *Queries) UpdateUserLoginLastTime(ctx context.Context, id int64) (int64, error) { result, err := q.db.Exec(ctx, updateUserLoginLastTime, id) if err != nil { diff --git a/code/base-project/base-go-v3/genpb.exe b/code/base-project/base-go-v3/genpb.exe deleted file mode 100644 index cff080ba..00000000 Binary files a/code/base-project/base-go-v3/genpb.exe and /dev/null differ diff --git a/code/base-project/base-go-v3/go.mod b/code/base-project/base-go-v3/go.mod index 915d2328..d2b0c40f 100644 --- a/code/base-project/base-go-v3/go.mod +++ b/code/base-project/base-go-v3/go.mod @@ -28,8 +28,10 @@ require ( github.com/cloudwego/netpoll v0.7.2 // indirect github.com/elastic/pkcs8 v1.0.0 // indirect github.com/fsnotify/fsnotify v1.9.0 // indirect + github.com/go-errors/errors v1.5.1 // indirect github.com/go-openapi/inflect v0.21.3 // indirect github.com/go-sql-driver/mysql v1.9.3 // indirect + github.com/go-viper/mapstructure/v2 v2.4.0 // indirect github.com/goccy/go-json v0.10.5 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/go-cmp v0.7.0 // indirect @@ -44,6 +46,15 @@ require ( github.com/klauspost/cpuid/v2 v2.3.0 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/nyaruka/phonenumbers v1.6.7 // indirect + github.com/pelletier/go-toml/v2 v2.2.4 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/sagikazarmark/locafero v0.11.0 // indirect + github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect + github.com/spf13/afero v1.15.0 // indirect + github.com/spf13/cast v1.10.0 // indirect + github.com/spf13/pflag v1.0.10 // indirect + github.com/spf13/viper v1.21.0 // indirect + github.com/subosito/gotenv v1.6.0 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect github.com/tidwall/gjson v1.18.0 // indirect github.com/tidwall/match v1.2.0 // indirect @@ -52,6 +63,7 @@ require ( github.com/zclconf/go-cty v1.17.0 // indirect github.com/zclconf/go-cty-yaml v1.1.0 // indirect go.uber.org/multierr v1.11.0 // indirect + go.yaml.in/yaml/v3 v3.0.4 // indirect golang.org/x/arch v0.23.0 // indirect golang.org/x/crypto v0.45.0 // indirect golang.org/x/exp v0.0.0-20251125195548-87e1e737ad39 // indirect diff --git a/code/base-project/base-go-v3/go.sum b/code/base-project/base-go-v3/go.sum index adc20160..96999d80 100644 --- a/code/base-project/base-go-v3/go.sum +++ b/code/base-project/base-go-v3/go.sum @@ -45,6 +45,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= +github.com/go-errors/errors v1.5.1 h1:ZwEMSLRCapFLflTpT7NKaAc7ukJ8ZPEjzlxt8rPN8bk= +github.com/go-errors/errors v1.5.1/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-openapi/inflect v0.21.3 h1:TmQvw+9eLrsNp4X0BBQacEZZtAnzk2z1FaLdQQJsDiU= github.com/go-openapi/inflect v0.21.3/go.mod h1:INezMuUu7SJQc2AyR3WO0DqqYUJSj8Kb4hBd7WtjlAw= github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= @@ -52,6 +54,8 @@ github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1 github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= +github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs= +github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI= @@ -120,12 +124,28 @@ github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= +github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc= +github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik= +github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw= +github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U= +github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I= +github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg= +github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY= +github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= +github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU= +github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -142,6 +162,8 @@ github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8 github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/tidwall/gjson v1.9.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= @@ -169,6 +191,8 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc= go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.23.0 h1:lKF64A2jF6Zd8L0knGltUnegD62JMFBiCPBmQpToHhg= golang.org/x/arch v0.23.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A= diff --git a/code/base-project/base-go-v3/idl/auth/auth.proto b/code/base-project/base-go-v3/idl/auth.proto similarity index 74% rename from code/base-project/base-go-v3/idl/auth/auth.proto rename to code/base-project/base-go-v3/idl/auth.proto index bce6d304..45f7f678 100644 --- a/code/base-project/base-go-v3/idl/auth/auth.proto +++ b/code/base-project/base-go-v3/idl/auth.proto @@ -16,8 +16,8 @@ message LoginDefaultResp { string refreshToken = 2; int64 userId = 3; string username = 4; - int64 seqNo = 5; - int64 gender = 6; + int32 seqNo = 5; + int32 gender = 6; } message RegisterDefaultReq { @@ -29,6 +29,13 @@ message RegisterDefaultResp { } +message RefreshAccessTokenReq { +} + +message RefreshAccessTokenResp { + string accessToken = 1; +} + service LoginService { rpc LoginDefault(LoginDefaultReq) returns(LoginDefaultResp) { option (api.post) = "/auth/login/default"; @@ -40,3 +47,9 @@ service RegisterService { option (api.post) = "/auth/register/default"; } } + +service TokenService { + rpc RefreshAccessToken(RefreshAccessTokenReq) returns(RefreshAccessTokenResp) { + option (api.post) = "/auth/refreshToken"; + } +} \ No newline at end of file diff --git a/code/base-project/base-go-v3/idl/auth/login.proto b/code/base-project/base-go-v3/idl/auth/login.proto deleted file mode 100644 index a31f5a39..00000000 --- a/code/base-project/base-go-v3/idl/auth/login.proto +++ /dev/null @@ -1,28 +0,0 @@ -syntax = "proto3"; - -package auth; - -option go_package = "auth/login"; - -import "api.proto"; - -message LoginDefaultReq { - string Account = 1[(api.body)="account",(api.vd)="$!=''"]; - string Password = 2[(api.body)="password",(api.vd)="$!=''"]; -} - -message LoginDefaultResp { - string token = 1; - string refreshToken = 2; - int64 userId = 3; - string username = 4; - int64 seqNo = 5; - int64 gender = 6; -} - -service LoginService { - rpc LoginDefault(LoginDefaultReq) returns(LoginDefaultResp) { - option (api.post) = "/auth/login/default"; - } -} - diff --git a/code/base-project/base-go-v3/idl/auth/register.proto b/code/base-project/base-go-v3/idl/auth/register.proto deleted file mode 100644 index 57d668bf..00000000 --- a/code/base-project/base-go-v3/idl/auth/register.proto +++ /dev/null @@ -1,23 +0,0 @@ -syntax = "proto3"; - -package auth; - -option go_package = "auth/register"; - -import "api.proto"; - - -message RegisterDefaultReq { - string Account = 1[(api.body)="account",(api.vd)="$!=''"]; - string Password = 2[(api.body)="password",(api.vd)="$!=''"]; -} - -message RegisterDefaultResp { - -} - -service RegisterService { - rpc RegisterDefault(RegisterDefaultReq) returns(RegisterDefaultResp) { - option (api.post) = "/auth/register/default"; - } -} diff --git a/code/base-project/base-go-v3/idl/money_category.proto b/code/base-project/base-go-v3/idl/money_category.proto new file mode 100644 index 00000000..39211941 --- /dev/null +++ b/code/base-project/base-go-v3/idl/money_category.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; + + +package money_category; + +option go_package = "money_category"; + +import "api.proto"; + + +message QueryUserMoneyCategoryReq{} +message UserMoneyCategory { + int64 id = 1; + string name = 2; + string icon = 3; + int32 type = 4; + int32 sort_number = 5; +} + +message QueryUserMoneyCategoryResp { + repeated UserMoneyCategory categories = 1; +} +service MoneyCategoryService { + rpc QueryUserMoneyCategory(QueryUserMoneyCategoryReq) returns (QueryUserMoneyCategoryResp){ + option (api.get) = '/money/category'; + }; +} \ No newline at end of file diff --git a/code/base-project/base-go-v3/logx/log.go b/code/base-project/base-go-v3/logx/log.go index ca415573..8a81f235 100644 --- a/code/base-project/base-go-v3/logx/log.go +++ b/code/base-project/base-go-v3/logx/log.go @@ -6,6 +6,7 @@ import ( "sync" "time" + "cn/oneao/base-go/conf" "github.com/cloudwego/hertz/pkg/common/hlog" "go.uber.org/zap" "go.uber.org/zap/zapcore" @@ -13,46 +14,63 @@ import ( ) var ( - // 暴露底层 zap logger 供 logreq 使用 - zapLogger *zap.Logger + zapLogger *zap.Logger + mu sync.Mutex + currentDay = make(map[string]string) + currentSync = make(map[string]zapcore.WriteSyncer) ) +// InitLog 从配置初始化日志 func InitLog() { - dynamicLevel := zap.NewAtomicLevel() + cfg := conf.GetConf().Log // LogConfig 从 YAML 读取 - dynamicLevel.SetLevel(zap.DebugLevel) + if cfg.Dir == "" { + cfg.Dir = "./logs" + } + if cfg.MaxSize <= 0 { + cfg.MaxSize = 10 + } + if cfg.MaxBackups <= 0 { + cfg.MaxBackups = 30 + } + if cfg.MaxAge <= 0 { + cfg.MaxAge = 7 + } + + dynamicLevel := zap.NewAtomicLevel() + dynamicLevel.SetLevel(LogLevel()) logger := NewLogger( WithCores([]CoreConfig{ { - Enc: zapcore.NewJSONEncoder(humanEncoderConfig()), + Enc: zapcore.NewConsoleEncoder(consoleEncoderConfig()), Ws: zapcore.AddSync(os.Stdout), Lvl: dynamicLevel, }, { Enc: zapcore.NewJSONEncoder(humanEncoderConfig()), - Ws: getWriteSyncer("./logs/debug"), + Ws: getWriteSyncer(fmt.Sprintf("%s/debug", cfg.Dir), &cfg), Lvl: zap.LevelEnablerFunc(func(lev zapcore.Level) bool { return lev == zap.DebugLevel }), }, { Enc: zapcore.NewJSONEncoder(humanEncoderConfig()), - Ws: getWriteSyncer("./logs/info"), + Ws: getWriteSyncer(fmt.Sprintf("%s/info", cfg.Dir), &cfg), Lvl: zap.LevelEnablerFunc(func(lev zapcore.Level) bool { return lev == zap.InfoLevel }), }, { Enc: zapcore.NewJSONEncoder(humanEncoderConfig()), - Ws: getWriteSyncer("./logs/warn"), + Ws: getWriteSyncer(fmt.Sprintf("%s/warn", cfg.Dir), &cfg), Lvl: zap.LevelEnablerFunc(func(lev zapcore.Level) bool { return lev == zap.WarnLevel }), }, { Enc: zapcore.NewJSONEncoder(humanEncoderConfig()), - Ws: getWriteSyncer("./logs/error"), + Ws: getWriteSyncer(fmt.Sprintf("%s/error", cfg.Dir), &cfg), Lvl: zap.LevelEnablerFunc(func(lev zapcore.Level) bool { return lev >= zap.ErrorLevel }), @@ -61,35 +79,10 @@ func InitLog() { ) hlog.SetLogger(logger) - zapLogger = logger.Logger() } -// humanEncoderConfig copy from zap -func humanEncoderConfig() zapcore.EncoderConfig { - return zapcore.EncoderConfig{ - MessageKey: "Message", - LevelKey: "Level", - NameKey: "Name", - TimeKey: "Ts", - CallerKey: "Caller", - FunctionKey: "Func", - StacktraceKey: "Stacktrace", - LineEnding: "\n", - EncodeTime: zapcore.ISO8601TimeEncoder, - EncodeLevel: zapcore.LowercaseLevelEncoder, - EncodeDuration: zapcore.SecondsDurationEncoder, - EncodeCaller: zapcore.ShortCallerEncoder, - } -} - -var ( - mu sync.Mutex - currentDay = make(map[string]string) - currentSync = make(map[string]zapcore.WriteSyncer) -) - -func getWriteSyncer(basePath string) zapcore.WriteSyncer { +func getWriteSyncer(basePath string, cfg *conf.LogConfig) zapcore.WriteSyncer { mu.Lock() defer mu.Unlock() @@ -100,21 +93,68 @@ func getWriteSyncer(basePath string) zapcore.WriteSyncer { currentSync[basePath] = zapcore.AddSync(&lumberjack.Logger{ Filename: file, - MaxSize: 10, - MaxBackups: 50000, - MaxAge: 5, - Compress: true, + MaxSize: cfg.MaxSize, + MaxBackups: cfg.MaxBackups, + MaxAge: cfg.MaxAge, + Compress: cfg.Compress, LocalTime: true, }) } return currentSync[basePath] } -func Sync() error { - if zapLogger != nil { - return zapLogger.Sync() + +func LogLevel() zapcore.Level { + level := conf.GetConf().Log.Level + switch level { + case "trace": + return zapcore.DebugLevel + case "debug": + return zapcore.DebugLevel + case "info": + return zapcore.InfoLevel + case "warn": + return zapcore.WarnLevel + case "error": + return zapcore.ErrorLevel + case "dpanic": + return zapcore.DPanicLevel + case "panic": + return zapcore.PanicLevel + case "fatal": + return zapcore.FatalLevel + default: + return zapcore.InfoLevel } - return nil } -func GetZapLogger() *zap.Logger { - return zapLogger + +func consoleEncoderConfig() zapcore.EncoderConfig { + return zapcore.EncoderConfig{ + MessageKey: "msg", + LevelKey: "level", + TimeKey: "ts", + EncodeTime: customTimeEncoder, + EncodeLevel: zapcore.CapitalColorLevelEncoder, + EncodeCaller: zapcore.ShortCallerEncoder, + } +} + +func humanEncoderConfig() zapcore.EncoderConfig { + return zapcore.EncoderConfig{ + MessageKey: "Message", + LevelKey: "Level", + NameKey: "Name", + TimeKey: "Ts", + CallerKey: "Caller", + FunctionKey: "Func", + StacktraceKey: "Stacktrace", + LineEnding: "\n", + EncodeTime: customTimeEncoder, + EncodeLevel: zapcore.LowercaseLevelEncoder, + EncodeDuration: zapcore.SecondsDurationEncoder, + EncodeCaller: zapcore.ShortCallerEncoder, + } +} + +func customTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) { + enc.AppendString(t.Format("2006-01-02 15:04:05.000")) } diff --git a/code/base-project/base-go-v3/main.go b/code/base-project/base-go-v3/main.go index 4cbc294c..faefc8de 100644 --- a/code/base-project/base-go-v3/main.go +++ b/code/base-project/base-go-v3/main.go @@ -1,13 +1,38 @@ -// Code generated by hertz generator. - package main import ( + "cn/oneao/base-go/biz/router/middleware" + "cn/oneao/base-go/conf" + "cn/oneao/base-go/db" + "cn/oneao/base-go/logx" + "cn/oneao/base-go/utils/idgen" + "cn/oneao/base-go/utils/jwtx" "github.com/cloudwego/hertz/pkg/app/server" + "github.com/hertz-contrib/requestid" ) func main() { - h := server.Default() + // 初始化雪花id + options := idgen.NewIdGeneratorOptions(conf.GetConf().Snowflake.WorkerID) + idgen.SetIdGenerator(options) + + // 数据库 + db.InitDB() + // 日志 + logx.InitLog() + // jwt + jwtx.InitJwt() + + h := server.Default( + server.WithBasePath(conf.GetConf().Server.BaseUrl), + server.WithHostPorts(":"+conf.GetConf().Server.Port), + ) + + // 全局中间件 + h.Use(requestid.New()) + h.Use(middleware.Log()) + h.Use(middleware.Error()) + h.Use(middleware.Auth()) register(h) h.Spin() diff --git a/code/base-project/base-go-v3/middleware/error.go b/code/base-project/base-go-v3/middleware/error.go deleted file mode 100644 index 8c71c82c..00000000 --- a/code/base-project/base-go-v3/middleware/error.go +++ /dev/null @@ -1,17 +0,0 @@ -package middleware - -import ( - "context" - - "github.com/cloudwego/hertz/pkg/app" -) - -// Error 中间件 -func Error() app.HandlerFunc { - return func(ctx context.Context, c *app.RequestContext) { - c.Next(ctx) - - if err := c.Errors.Last(); err != nil { - } - } -} diff --git a/code/base-project/base-go-v3/router.go b/code/base-project/base-go-v3/router.go deleted file mode 100644 index 969e1cbb..00000000 --- a/code/base-project/base-go-v3/router.go +++ /dev/null @@ -1,15 +0,0 @@ -// Code generated by hertz generator. - -package main - -import ( - handler "cn/oneao/base-go/biz/handler" - "github.com/cloudwego/hertz/pkg/app/server" -) - -// customizeRegister registers customize routers. -func customizedRegister(r *server.Hertz) { - r.GET("/ping", handler.Ping) - - // your code ... -} diff --git a/code/base-project/base-go-v3/router_gen.go b/code/base-project/base-go-v3/router_gen.go index 286bf31c..c3ea3c8f 100644 --- a/code/base-project/base-go-v3/router_gen.go +++ b/code/base-project/base-go-v3/router_gen.go @@ -12,5 +12,4 @@ func register(r *server.Hertz) { router.GeneratedRegister(r) - customizedRegister(r) } diff --git a/code/base-project/base-go-v3/sqlc.yaml b/code/base-project/base-go-v3/sqlc.yaml index d1aaa894..aa6d6207 100644 --- a/code/base-project/base-go-v3/sqlc.yaml +++ b/code/base-project/base-go-v3/sqlc.yaml @@ -5,6 +5,6 @@ sql: schema: "db/schema.sql" # schema.sql文件的路径,该文件主要用于存储DDL gen: go: - package: "sqlcg" # 模块的包名 + package: "dbtype" # 模块的包名 out: "db/sqlc" # 代码生成路径 sql_package: "pgx/v5" diff --git a/code/base-project/base-go-v3/utils/errorx/errorx.go b/code/base-project/base-go-v3/utils/errorx/errorx.go new file mode 100644 index 00000000..3c467a23 --- /dev/null +++ b/code/base-project/base-go-v3/utils/errorx/errorx.go @@ -0,0 +1,29 @@ +package errorx + +import ( + "database/sql" + "github.com/cloudwego/hertz/pkg/app" + "github.com/jackc/pgx/v5" + "github.com/pkg/errors" +) + +// Wrap 包装 error,附加调用栈 +func Wrap(err error) error { + if err == nil { + return nil + } + return errors.WithStack(err) +} + +// AddError 简化版,自动 wrap 并注册到 ctx +func AddError(c *app.RequestContext, err error) { + if err == nil { + return + } + _ = c.Error(Wrap(err)) // 自动 wrap 并注册 +} + +// IsNotFound 判断 err 是否因为数据库中没找到数据 +func IsNotFound(err error) bool { + return errors.Is(err, sql.ErrNoRows) || errors.Is(err, pgx.ErrNoRows) +} diff --git a/code/base-project/base-go-v3/utils/jwtx/jwt.go b/code/base-project/base-go-v3/utils/jwtx/jwt.go index 6fc39190..71a57497 100644 --- a/code/base-project/base-go-v3/utils/jwtx/jwt.go +++ b/code/base-project/base-go-v3/utils/jwtx/jwt.go @@ -1,37 +1,91 @@ package jwtx import ( - "cn/oneao/base-go/config" + "cn/oneao/base-go/conf" + "sync" "time" "github.com/golang-jwt/jwt/v4" ) -// CustomClaims 自定义 payload,可扩展其他信息 type CustomClaims struct { UserID int64 `json:"user_id"` jwt.RegisteredClaims } -// TokenResult 用于返回验证结果 type TokenResult struct { Claims *CustomClaims IsValid bool IsExpired bool } -// CreateAccessToken 创建 Access Token,只返回 token 和 error +type jwtManager struct { + secret string + accessExpiry time.Duration + refreshExpiry time.Duration +} + +var ( + manager *jwtManager + once sync.Once +) + +// InitJwt 初始化全局 JWT 配置,只能调用一次 +func InitJwt() { + once.Do(func() { + manager = &jwtManager{ + secret: conf.GetConf().JWT.Secret, + accessExpiry: conf.GetConf().JWT.AccessExpiry, + refreshExpiry: conf.GetConf().JWT.RefreshExpiry, + } + }) +} + +// CreateAccessToken 全局函数创建 Access Token func CreateAccessToken(userID int64) (string, error) { - return createToken(userID, config.App.JWT.AccessExpiry) + return manager.createToken(userID, manager.accessExpiry) } -// CreateRefreshToken 创建 Refresh Token,只返回 token 和 error +// CreateRefreshToken 全局函数创建 Refresh Token func CreateRefreshToken(userID int64) (string, error) { - return createToken(userID, config.App.JWT.RefreshExpiry) + return manager.createToken(userID, manager.refreshExpiry) } -// 内部方法,根据过期时间生成 token -func createToken(userID int64, expiry time.Duration) (string, error) { +// VerifyToken 全局函数验证 Token +func VerifyToken(tokenString string) TokenResult { + result := TokenResult{IsValid: false, IsExpired: false} + + if tokenString == "" || manager == nil { + return result + } + + token, err := jwt.ParseWithClaims(tokenString, &CustomClaims{}, func(token *jwt.Token) (interface{}, error) { + return []byte(manager.secret), nil + }) + + if token == nil { + return result + } + + claims, ok := token.Claims.(*CustomClaims) + if !ok { + return result + } + + if err != nil || !token.Valid { + return result + } + + result.Claims = claims + result.IsValid = true + if claims.ExpiresAt != nil && time.Now().After(claims.ExpiresAt.Time) { + result.IsExpired = true + } + return result +} + +// 内部方法,生成 Token +func (j *jwtManager) createToken(userID int64, expiry time.Duration) (string, error) { claims := &CustomClaims{ UserID: userID, RegisteredClaims: jwt.RegisteredClaims{ @@ -41,65 +95,13 @@ func createToken(userID int64, expiry time.Duration) (string, error) { switch { case expiry > 0: - expireAt := time.Now().Add(expiry) - claims.ExpiresAt = jwt.NewNumericDate(expireAt) + claims.ExpiresAt = jwt.NewNumericDate(time.Now().Add(expiry)) case expiry == -1: claims.ExpiresAt = nil // 永不过期 default: - expireAt := time.Now().Add(time.Hour) - claims.ExpiresAt = jwt.NewNumericDate(expireAt) + claims.ExpiresAt = jwt.NewNumericDate(time.Now().Add(time.Hour)) } token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) - signed, err := token.SignedString([]byte(config.App.JWT.Secret)) - if err != nil { - return "", err - } - - return signed, nil -} - -// VerifyToken 验证 token 并返回结构化结果 -func VerifyToken(tokenString string) TokenResult { - result := TokenResult{ - IsValid: false, - IsExpired: false, - } - - // 🧩 1. token 为空 - if tokenString == "" { - return result - } - - // 🧩 2. 解析 token - token, err := jwt.ParseWithClaims(tokenString, &CustomClaims{}, func(token *jwt.Token) (interface{}, error) { - return []byte(config.App.JWT.Secret), nil - }) - - // 🧩 3. token 为 nil(解析异常) - if token == nil { - return result - } - - // 🧩 4. 提取 claims 并验证 - claims, ok := token.Claims.(*CustomClaims) - if !ok { - return result - } - - // 🧩 5. 解析失败或签名无效 - if err != nil || !token.Valid { - return result - } - - // ✅ 6. 填充结果 - result.Claims = claims - result.IsValid = true - - // 🧩 7. 检查是否过期 - if claims.ExpiresAt != nil && time.Now().After(claims.ExpiresAt.Time) { - result.IsExpired = true - } - - return result + return token.SignedString([]byte(j.secret)) } diff --git a/code/base-project/base-go-v3/utils/pathx/path.go b/code/base-project/base-go-v3/utils/pathx/path.go new file mode 100644 index 00000000..8e3bbcbc --- /dev/null +++ b/code/base-project/base-go-v3/utils/pathx/path.go @@ -0,0 +1,19 @@ +package pathx + +import ( + "cn/oneao/base-go/conf" + "strings" +) + +// MatchPath 判断给定路径是否在白名单中 +func MatchPath(path string, whitelist []string) bool { + baseUrl := conf.GetConf().Server.BaseUrl + + for _, p := range whitelist { + fullPath := baseUrl + p + if strings.HasPrefix(path, fullPath) { + return true + } + } + return false +} diff --git a/editbuyin.jsp b/editbuyin.jsp deleted file mode 100644 index bec427a3..00000000 --- a/editbuyin.jsp +++ /dev/null @@ -1,5380 +0,0 @@ -<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %> - <%@ include file="../ini.jsp" %> - <% String id=request.getParameter("id"); if (id==null) { id="" ; } String father=request.getParameter("father"); if - (father==null) { father="" ; } %> - - - - - 买箱入库 - - - - - - - - - - - - - -
-
-
- - - - - - - -
-
-
- 买箱入库 -
-
-
- - - - -
-
- - -
-
- - - -
- -
- - -
- -
- - -
-
- - - - -
-
- - -
- -
- - - -
-
- - -
-
- - - -
- -
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- -
- - -
- - - -
- -
-
- - >
-
-
-
-
- -
- -
-
-
-
- - - - - - - - - - - - - -
- - - - - - - - - - - -
- 删除日志 -
- -
- - - - -
- - -
-
- -
-
- 删除 -
- - -
- 栏位设定 -
-
-
- - - \ No newline at end of file