first commit
This commit is contained in:
31
apps/sentinel/Dockerfile
Normal file
31
apps/sentinel/Dockerfile
Normal file
@@ -0,0 +1,31 @@
|
||||
FROM golang:alpine AS builder
|
||||
|
||||
LABEL stage=gobuilder
|
||||
|
||||
ENV CGO_ENABLED 0
|
||||
ENV GOPROXY https://goproxy.cn,direct
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
||||
|
||||
RUN apk update --no-cache && apk add --no-cache tzdata
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
ADD go.mod .
|
||||
ADD go.sum .
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
COPY apps/sentinel/etc /app/etc
|
||||
RUN go build -ldflags="-s -w" -o /app/sentinel apps/sentinel/.\sentinel.go
|
||||
|
||||
|
||||
FROM scratch
|
||||
|
||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai
|
||||
ENV TZ Asia/Shanghai
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/sentinel /app/sentinel
|
||||
COPY --from=builder /app/etc /app/etc
|
||||
|
||||
CMD ["./sentinel", "-f", "etc/sentinel.yaml"]
|
||||
91
apps/sentinel/client/product/product.go
Normal file
91
apps/sentinel/client/product/product.go
Normal file
@@ -0,0 +1,91 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.2
|
||||
// Source: sentinel.proto
|
||||
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type (
|
||||
CreateProductRequest = sentinel.CreateProductRequest
|
||||
CreateSecretRequest = sentinel.CreateSecretRequest
|
||||
CreateUserProductRequest = sentinel.CreateUserProductRequest
|
||||
CreateWhitelistRequest = sentinel.CreateWhitelistRequest
|
||||
DeleteProductRequest = sentinel.DeleteProductRequest
|
||||
DeleteSecretRequest = sentinel.DeleteSecretRequest
|
||||
DeleteUserProductRequest = sentinel.DeleteUserProductRequest
|
||||
DeleteWhitelistRequest = sentinel.DeleteWhitelistRequest
|
||||
GetRecordByIdRequest = sentinel.GetRecordByIdRequest
|
||||
GetSecretBySecretIdRequest = sentinel.GetSecretBySecretIdRequest
|
||||
MatchResponse = sentinel.MatchResponse
|
||||
MatchWhitelistByIpRequest = sentinel.MatchWhitelistByIpRequest
|
||||
MatchingUserIdProductCodeRequest = sentinel.MatchingUserIdProductCodeRequest
|
||||
PageListRequest = sentinel.PageListRequest
|
||||
Product = sentinel.Product
|
||||
ProductResponse = sentinel.ProductResponse
|
||||
Secret = sentinel.Secret
|
||||
SecretResponse = sentinel.SecretResponse
|
||||
UpdateProductRequest = sentinel.UpdateProductRequest
|
||||
UpdateSecretRequest = sentinel.UpdateSecretRequest
|
||||
UpdateUserProductRequest = sentinel.UpdateUserProductRequest
|
||||
UpdateWhitelistRequest = sentinel.UpdateWhitelistRequest
|
||||
UserProductEmptyResponse = sentinel.UserProductEmptyResponse
|
||||
UserProductItem = sentinel.UserProductItem
|
||||
UserProductResponse = sentinel.UserProductResponse
|
||||
UserProuctPageListRequest = sentinel.UserProuctPageListRequest
|
||||
WhitePageListRequest = sentinel.WhitePageListRequest
|
||||
Whitelist = sentinel.Whitelist
|
||||
WhitelistResponse = sentinel.WhitelistResponse
|
||||
|
||||
ProductZrpcClient interface {
|
||||
// Product methods
|
||||
CreateProduct(ctx context.Context, in *CreateProductRequest, opts ...grpc.CallOption) (*Product, error)
|
||||
UpdateProduct(ctx context.Context, in *UpdateProductRequest, opts ...grpc.CallOption) (*Product, error)
|
||||
DeleteProduct(ctx context.Context, in *DeleteProductRequest, opts ...grpc.CallOption) (*Product, error)
|
||||
GetProductPageList(ctx context.Context, in *PageListRequest, opts ...grpc.CallOption) (*ProductResponse, error)
|
||||
GetProductById(ctx context.Context, in *GetRecordByIdRequest, opts ...grpc.CallOption) (*Product, error)
|
||||
}
|
||||
|
||||
defaultProductZrpcClient struct {
|
||||
cli zrpc.Client
|
||||
}
|
||||
)
|
||||
|
||||
func NewProductZrpcClient(cli zrpc.Client) ProductZrpcClient {
|
||||
return &defaultProductZrpcClient{
|
||||
cli: cli,
|
||||
}
|
||||
}
|
||||
|
||||
// Product methods
|
||||
func (m *defaultProductZrpcClient) CreateProduct(ctx context.Context, in *CreateProductRequest, opts ...grpc.CallOption) (*Product, error) {
|
||||
client := sentinel.NewProductClient(m.cli.Conn())
|
||||
return client.CreateProduct(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultProductZrpcClient) UpdateProduct(ctx context.Context, in *UpdateProductRequest, opts ...grpc.CallOption) (*Product, error) {
|
||||
client := sentinel.NewProductClient(m.cli.Conn())
|
||||
return client.UpdateProduct(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultProductZrpcClient) DeleteProduct(ctx context.Context, in *DeleteProductRequest, opts ...grpc.CallOption) (*Product, error) {
|
||||
client := sentinel.NewProductClient(m.cli.Conn())
|
||||
return client.DeleteProduct(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultProductZrpcClient) GetProductPageList(ctx context.Context, in *PageListRequest, opts ...grpc.CallOption) (*ProductResponse, error) {
|
||||
client := sentinel.NewProductClient(m.cli.Conn())
|
||||
return client.GetProductPageList(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultProductZrpcClient) GetProductById(ctx context.Context, in *GetRecordByIdRequest, opts ...grpc.CallOption) (*Product, error) {
|
||||
client := sentinel.NewProductClient(m.cli.Conn())
|
||||
return client.GetProductById(ctx, in, opts...)
|
||||
}
|
||||
79
apps/sentinel/client/secret/secret.go
Normal file
79
apps/sentinel/client/secret/secret.go
Normal file
@@ -0,0 +1,79 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.2
|
||||
// Source: sentinel.proto
|
||||
|
||||
package secret
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type (
|
||||
CreateProductRequest = sentinel.CreateProductRequest
|
||||
CreateSecretRequest = sentinel.CreateSecretRequest
|
||||
CreateUserProductRequest = sentinel.CreateUserProductRequest
|
||||
CreateWhitelistRequest = sentinel.CreateWhitelistRequest
|
||||
DeleteProductRequest = sentinel.DeleteProductRequest
|
||||
DeleteSecretRequest = sentinel.DeleteSecretRequest
|
||||
DeleteUserProductRequest = sentinel.DeleteUserProductRequest
|
||||
DeleteWhitelistRequest = sentinel.DeleteWhitelistRequest
|
||||
GetRecordByIdRequest = sentinel.GetRecordByIdRequest
|
||||
GetSecretBySecretIdRequest = sentinel.GetSecretBySecretIdRequest
|
||||
MatchResponse = sentinel.MatchResponse
|
||||
MatchWhitelistByIpRequest = sentinel.MatchWhitelistByIpRequest
|
||||
MatchingUserIdProductCodeRequest = sentinel.MatchingUserIdProductCodeRequest
|
||||
PageListRequest = sentinel.PageListRequest
|
||||
Product = sentinel.Product
|
||||
ProductResponse = sentinel.ProductResponse
|
||||
Secret = sentinel.Secret
|
||||
SecretResponse = sentinel.SecretResponse
|
||||
UpdateProductRequest = sentinel.UpdateProductRequest
|
||||
UpdateSecretRequest = sentinel.UpdateSecretRequest
|
||||
UpdateUserProductRequest = sentinel.UpdateUserProductRequest
|
||||
UpdateWhitelistRequest = sentinel.UpdateWhitelistRequest
|
||||
UserProductEmptyResponse = sentinel.UserProductEmptyResponse
|
||||
UserProductItem = sentinel.UserProductItem
|
||||
UserProductResponse = sentinel.UserProductResponse
|
||||
UserProuctPageListRequest = sentinel.UserProuctPageListRequest
|
||||
WhitePageListRequest = sentinel.WhitePageListRequest
|
||||
Whitelist = sentinel.Whitelist
|
||||
WhitelistResponse = sentinel.WhitelistResponse
|
||||
|
||||
SecretZrpcClient interface {
|
||||
// Secret methods
|
||||
CreateSecret(ctx context.Context, in *CreateSecretRequest, opts ...grpc.CallOption) (*Secret, error)
|
||||
GetSecretByUserId(ctx context.Context, in *GetRecordByIdRequest, opts ...grpc.CallOption) (*Secret, error)
|
||||
GetSecretBySecretId(ctx context.Context, in *GetSecretBySecretIdRequest, opts ...grpc.CallOption) (*Secret, error)
|
||||
}
|
||||
|
||||
defaultSecretZrpcClient struct {
|
||||
cli zrpc.Client
|
||||
}
|
||||
)
|
||||
|
||||
func NewSecretZrpcClient(cli zrpc.Client) SecretZrpcClient {
|
||||
return &defaultSecretZrpcClient{
|
||||
cli: cli,
|
||||
}
|
||||
}
|
||||
|
||||
// Secret methods
|
||||
func (m *defaultSecretZrpcClient) CreateSecret(ctx context.Context, in *CreateSecretRequest, opts ...grpc.CallOption) (*Secret, error) {
|
||||
client := sentinel.NewSecretClient(m.cli.Conn())
|
||||
return client.CreateSecret(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultSecretZrpcClient) GetSecretByUserId(ctx context.Context, in *GetRecordByIdRequest, opts ...grpc.CallOption) (*Secret, error) {
|
||||
client := sentinel.NewSecretClient(m.cli.Conn())
|
||||
return client.GetSecretByUserId(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultSecretZrpcClient) GetSecretBySecretId(ctx context.Context, in *GetSecretBySecretIdRequest, opts ...grpc.CallOption) (*Secret, error) {
|
||||
client := sentinel.NewSecretClient(m.cli.Conn())
|
||||
return client.GetSecretBySecretId(ctx, in, opts...)
|
||||
}
|
||||
79
apps/sentinel/client/userproduct/userproduct.go
Normal file
79
apps/sentinel/client/userproduct/userproduct.go
Normal file
@@ -0,0 +1,79 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.2
|
||||
// Source: sentinel.proto
|
||||
|
||||
package userproduct
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type (
|
||||
CreateProductRequest = sentinel.CreateProductRequest
|
||||
CreateSecretRequest = sentinel.CreateSecretRequest
|
||||
CreateUserProductRequest = sentinel.CreateUserProductRequest
|
||||
CreateWhitelistRequest = sentinel.CreateWhitelistRequest
|
||||
DeleteProductRequest = sentinel.DeleteProductRequest
|
||||
DeleteSecretRequest = sentinel.DeleteSecretRequest
|
||||
DeleteUserProductRequest = sentinel.DeleteUserProductRequest
|
||||
DeleteWhitelistRequest = sentinel.DeleteWhitelistRequest
|
||||
GetRecordByIdRequest = sentinel.GetRecordByIdRequest
|
||||
GetSecretBySecretIdRequest = sentinel.GetSecretBySecretIdRequest
|
||||
MatchResponse = sentinel.MatchResponse
|
||||
MatchWhitelistByIpRequest = sentinel.MatchWhitelistByIpRequest
|
||||
MatchingUserIdProductCodeRequest = sentinel.MatchingUserIdProductCodeRequest
|
||||
PageListRequest = sentinel.PageListRequest
|
||||
Product = sentinel.Product
|
||||
ProductResponse = sentinel.ProductResponse
|
||||
Secret = sentinel.Secret
|
||||
SecretResponse = sentinel.SecretResponse
|
||||
UpdateProductRequest = sentinel.UpdateProductRequest
|
||||
UpdateSecretRequest = sentinel.UpdateSecretRequest
|
||||
UpdateUserProductRequest = sentinel.UpdateUserProductRequest
|
||||
UpdateWhitelistRequest = sentinel.UpdateWhitelistRequest
|
||||
UserProductEmptyResponse = sentinel.UserProductEmptyResponse
|
||||
UserProductItem = sentinel.UserProductItem
|
||||
UserProductResponse = sentinel.UserProductResponse
|
||||
UserProuctPageListRequest = sentinel.UserProuctPageListRequest
|
||||
WhitePageListRequest = sentinel.WhitePageListRequest
|
||||
Whitelist = sentinel.Whitelist
|
||||
WhitelistResponse = sentinel.WhitelistResponse
|
||||
|
||||
UserProduct interface {
|
||||
// UserProduct methods
|
||||
CreateUserProduct(ctx context.Context, in *CreateUserProductRequest, opts ...grpc.CallOption) (*UserProductEmptyResponse, error)
|
||||
GetUserProductPageList(ctx context.Context, in *UserProuctPageListRequest, opts ...grpc.CallOption) (*UserProductResponse, error)
|
||||
MatchingUserIdProductCode(ctx context.Context, in *MatchingUserIdProductCodeRequest, opts ...grpc.CallOption) (*MatchResponse, error)
|
||||
}
|
||||
|
||||
defaultUserProduct struct {
|
||||
cli zrpc.Client
|
||||
}
|
||||
)
|
||||
|
||||
func NewUserProduct(cli zrpc.Client) UserProduct {
|
||||
return &defaultUserProduct{
|
||||
cli: cli,
|
||||
}
|
||||
}
|
||||
|
||||
// UserProduct methods
|
||||
func (m *defaultUserProduct) CreateUserProduct(ctx context.Context, in *CreateUserProductRequest, opts ...grpc.CallOption) (*UserProductEmptyResponse, error) {
|
||||
client := sentinel.NewUserProductClient(m.cli.Conn())
|
||||
return client.CreateUserProduct(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultUserProduct) GetUserProductPageList(ctx context.Context, in *UserProuctPageListRequest, opts ...grpc.CallOption) (*UserProductResponse, error) {
|
||||
client := sentinel.NewUserProductClient(m.cli.Conn())
|
||||
return client.GetUserProductPageList(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultUserProduct) MatchingUserIdProductCode(ctx context.Context, in *MatchingUserIdProductCodeRequest, opts ...grpc.CallOption) (*MatchResponse, error) {
|
||||
client := sentinel.NewUserProductClient(m.cli.Conn())
|
||||
return client.MatchingUserIdProductCode(ctx, in, opts...)
|
||||
}
|
||||
91
apps/sentinel/client/whitelist/whitelist.go
Normal file
91
apps/sentinel/client/whitelist/whitelist.go
Normal file
@@ -0,0 +1,91 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.2
|
||||
// Source: sentinel.proto
|
||||
|
||||
package whitelist
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type (
|
||||
CreateProductRequest = sentinel.CreateProductRequest
|
||||
CreateSecretRequest = sentinel.CreateSecretRequest
|
||||
CreateUserProductRequest = sentinel.CreateUserProductRequest
|
||||
CreateWhitelistRequest = sentinel.CreateWhitelistRequest
|
||||
DeleteProductRequest = sentinel.DeleteProductRequest
|
||||
DeleteSecretRequest = sentinel.DeleteSecretRequest
|
||||
DeleteUserProductRequest = sentinel.DeleteUserProductRequest
|
||||
DeleteWhitelistRequest = sentinel.DeleteWhitelistRequest
|
||||
GetRecordByIdRequest = sentinel.GetRecordByIdRequest
|
||||
GetSecretBySecretIdRequest = sentinel.GetSecretBySecretIdRequest
|
||||
MatchResponse = sentinel.MatchResponse
|
||||
MatchWhitelistByIpRequest = sentinel.MatchWhitelistByIpRequest
|
||||
MatchingUserIdProductCodeRequest = sentinel.MatchingUserIdProductCodeRequest
|
||||
PageListRequest = sentinel.PageListRequest
|
||||
Product = sentinel.Product
|
||||
ProductResponse = sentinel.ProductResponse
|
||||
Secret = sentinel.Secret
|
||||
SecretResponse = sentinel.SecretResponse
|
||||
UpdateProductRequest = sentinel.UpdateProductRequest
|
||||
UpdateSecretRequest = sentinel.UpdateSecretRequest
|
||||
UpdateUserProductRequest = sentinel.UpdateUserProductRequest
|
||||
UpdateWhitelistRequest = sentinel.UpdateWhitelistRequest
|
||||
UserProductEmptyResponse = sentinel.UserProductEmptyResponse
|
||||
UserProductItem = sentinel.UserProductItem
|
||||
UserProductResponse = sentinel.UserProductResponse
|
||||
UserProuctPageListRequest = sentinel.UserProuctPageListRequest
|
||||
WhitePageListRequest = sentinel.WhitePageListRequest
|
||||
Whitelist = sentinel.Whitelist
|
||||
WhitelistResponse = sentinel.WhitelistResponse
|
||||
|
||||
WhitelistZrpcClient interface {
|
||||
// Whitelist methods
|
||||
CreateWhitelist(ctx context.Context, in *CreateWhitelistRequest, opts ...grpc.CallOption) (*Whitelist, error)
|
||||
UpdateWhitelist(ctx context.Context, in *UpdateWhitelistRequest, opts ...grpc.CallOption) (*Whitelist, error)
|
||||
DeleteWhitelist(ctx context.Context, in *DeleteWhitelistRequest, opts ...grpc.CallOption) (*Whitelist, error)
|
||||
GetWhitePageList(ctx context.Context, in *WhitePageListRequest, opts ...grpc.CallOption) (*WhitelistResponse, error)
|
||||
MatchWhitelistByIp(ctx context.Context, in *MatchWhitelistByIpRequest, opts ...grpc.CallOption) (*MatchResponse, error)
|
||||
}
|
||||
|
||||
defaultWhitelistZrpcClient struct {
|
||||
cli zrpc.Client
|
||||
}
|
||||
)
|
||||
|
||||
func NewWhitelistZrpcClient(cli zrpc.Client) WhitelistZrpcClient {
|
||||
return &defaultWhitelistZrpcClient{
|
||||
cli: cli,
|
||||
}
|
||||
}
|
||||
|
||||
// Whitelist methods
|
||||
func (m *defaultWhitelistZrpcClient) CreateWhitelist(ctx context.Context, in *CreateWhitelistRequest, opts ...grpc.CallOption) (*Whitelist, error) {
|
||||
client := sentinel.NewWhitelistClient(m.cli.Conn())
|
||||
return client.CreateWhitelist(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistZrpcClient) UpdateWhitelist(ctx context.Context, in *UpdateWhitelistRequest, opts ...grpc.CallOption) (*Whitelist, error) {
|
||||
client := sentinel.NewWhitelistClient(m.cli.Conn())
|
||||
return client.UpdateWhitelist(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistZrpcClient) DeleteWhitelist(ctx context.Context, in *DeleteWhitelistRequest, opts ...grpc.CallOption) (*Whitelist, error) {
|
||||
client := sentinel.NewWhitelistClient(m.cli.Conn())
|
||||
return client.DeleteWhitelist(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistZrpcClient) GetWhitePageList(ctx context.Context, in *WhitePageListRequest, opts ...grpc.CallOption) (*WhitelistResponse, error) {
|
||||
client := sentinel.NewWhitelistClient(m.cli.Conn())
|
||||
return client.GetWhitePageList(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistZrpcClient) MatchWhitelistByIp(ctx context.Context, in *MatchWhitelistByIpRequest, opts ...grpc.CallOption) (*MatchResponse, error) {
|
||||
client := sentinel.NewWhitelistClient(m.cli.Conn())
|
||||
return client.MatchWhitelistByIp(ctx, in, opts...)
|
||||
}
|
||||
11
apps/sentinel/etc/sentinel.yaml
Normal file
11
apps/sentinel/etc/sentinel.yaml
Normal file
@@ -0,0 +1,11 @@
|
||||
Name: sentinel.rpc
|
||||
ListenOn: 0.0.0.0:11002
|
||||
Etcd:
|
||||
Hosts:
|
||||
- 127.0.0.1:2379
|
||||
Key: sentinel.rpc
|
||||
DataSource: "tianyuanapi:g3h98u0291j@tcp(127.0.0.1:3307)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
CacheRedis:
|
||||
- Host: "127.0.0.1:6379"
|
||||
Pass: "" # Redis 密码,如果未设置则留空
|
||||
Type: "node" # 单节点模式
|
||||
12
apps/sentinel/internal/config/config.go
Normal file
12
apps/sentinel/internal/config/config.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
zrpc.RpcServerConf
|
||||
DataSource string // 数据库连接的 DSN 字符串
|
||||
CacheRedis cache.CacheConf // 缓存配置,使用 go-zero 自带的缓存配置结构体
|
||||
}
|
||||
42
apps/sentinel/internal/logic/product/createproductlogic.go
Normal file
42
apps/sentinel/internal/logic/product/createproductlogic.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package productlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/apps/sentinel/internal/model"
|
||||
"tianyuan-api/pkg/sqlutil"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateProductLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateProductLogic {
|
||||
return &CreateProductLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// Product methods
|
||||
func (l *CreateProductLogic) CreateProduct(in *sentinel.CreateProductRequest) (*sentinel.Product, error) {
|
||||
_, err := l.svcCtx.ProductsModel.Insert(l.ctx, &model.Products{
|
||||
ProductName: in.ProductName,
|
||||
ProductCode: in.ProductCode,
|
||||
ProductDescription: sqlutil.StringToNullString(in.ProductDescription),
|
||||
ProductContent: sqlutil.StringToNullString(in.ProductContent),
|
||||
ProductGroup: in.ProductGroup,
|
||||
ProductPrice: in.ProductPrice,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &sentinel.Product{}, nil
|
||||
}
|
||||
30
apps/sentinel/internal/logic/product/deleteproductlogic.go
Normal file
30
apps/sentinel/internal/logic/product/deleteproductlogic.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package productlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeleteProductLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDeleteProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteProductLogic {
|
||||
return &DeleteProductLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeleteProductLogic) DeleteProduct(in *sentinel.DeleteProductRequest) (*sentinel.Product, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &sentinel.Product{}, nil
|
||||
}
|
||||
42
apps/sentinel/internal/logic/product/getproductbyidlogic.go
Normal file
42
apps/sentinel/internal/logic/product/getproductbyidlogic.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package productlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/pkg/sqlutil"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetProductByIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetProductByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductByIdLogic {
|
||||
return &GetProductByIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetProductByIdLogic) GetProductById(in *sentinel.GetRecordByIdRequest) (*sentinel.Product, error) {
|
||||
product, err := l.svcCtx.ProductsModel.FindOne(l.ctx, in.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sentinel.Product{
|
||||
Id: product.Id,
|
||||
ProductName: product.ProductName,
|
||||
ProductCode: product.ProductCode,
|
||||
ProductPrice: product.ProductPrice,
|
||||
ProductDescription: sqlutil.NullStringToString(product.ProductDescription),
|
||||
ProductContent: sqlutil.NullStringToString(product.ProductContent),
|
||||
ProductGroup: product.ProductGroup,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package productlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/pkg/sqlutil"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetProductPageListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetProductPageListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductPageListLogic {
|
||||
return &GetProductPageListLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetProductPageListLogic) GetProductPageList(in *sentinel.PageListRequest) (*sentinel.ProductResponse, error) {
|
||||
products, total, err := l.svcCtx.ProductsModel.FindProductsList(l.ctx, in.Page, in.PageSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var list []*sentinel.Product
|
||||
for _, p := range products {
|
||||
list = append(list, &sentinel.Product{
|
||||
Id: p.Id,
|
||||
ProductName: p.ProductName,
|
||||
ProductCode: p.ProductCode,
|
||||
ProductDescription: sqlutil.NullStringToString(p.ProductDescription),
|
||||
ProductGroup: p.ProductGroup,
|
||||
ProductPrice: p.ProductPrice,
|
||||
})
|
||||
}
|
||||
return &sentinel.ProductResponse{
|
||||
Total: total,
|
||||
Products: list,
|
||||
}, nil
|
||||
}
|
||||
30
apps/sentinel/internal/logic/product/updateproductlogic.go
Normal file
30
apps/sentinel/internal/logic/product/updateproductlogic.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package productlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateProductLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateProductLogic {
|
||||
return &UpdateProductLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateProductLogic) UpdateProduct(in *sentinel.UpdateProductRequest) (*sentinel.Product, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &sentinel.Product{}, nil
|
||||
}
|
||||
46
apps/sentinel/internal/logic/secret/createsecretlogic.go
Normal file
46
apps/sentinel/internal/logic/secret/createsecretlogic.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package secretlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/apps/sentinel/internal/model"
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
"tianyuan-api/pkg/crypto"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateSecretLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateSecretLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateSecretLogic {
|
||||
return &CreateSecretLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// Secret methods
|
||||
func (l *CreateSecretLogic) CreateSecret(in *sentinel.CreateSecretRequest) (*sentinel.Secret, error) {
|
||||
secretId, err := crypto.GenerateSecretId()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
aesKey, err := crypto.GenerateSecretKey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = l.svcCtx.SecretsModel.Insert(l.ctx, &model.Secrets{
|
||||
UserId: in.UserId,
|
||||
SecretId: secretId,
|
||||
AesKey: aesKey,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &sentinel.Secret{}, nil
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package secretlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"tianyuan-api/apps/sentinel/internal/model"
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetSecretBySecretIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetSecretBySecretIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSecretBySecretIdLogic {
|
||||
return &GetSecretBySecretIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetSecretBySecretIdLogic) GetSecretBySecretId(in *sentinel.GetSecretBySecretIdRequest) (*sentinel.Secret, error) {
|
||||
secret, err := l.svcCtx.SecretsModel.FindOneBySecretId(l.ctx, in.SecretId)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
return nil, nil
|
||||
} else {
|
||||
return nil, err
|
||||
|
||||
}
|
||||
}
|
||||
return &sentinel.Secret{
|
||||
Id: secret.Id,
|
||||
UserId: secret.UserId,
|
||||
SecretId: secret.SecretId,
|
||||
AesKey: secret.AesKey,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package secretlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"tianyuan-api/apps/sentinel/internal/model"
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetSecretByUserIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetSecretByUserIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSecretByUserIdLogic {
|
||||
return &GetSecretByUserIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetSecretByUserIdLogic) GetSecretByUserId(in *sentinel.GetRecordByIdRequest) (*sentinel.Secret, error) {
|
||||
secretModel, err := l.svcCtx.SecretsModel.FindOneByUserId(l.ctx, in.Id)
|
||||
if err != nil {
|
||||
if err == model.ErrNotFound {
|
||||
return nil, errors.New("请先进行企业认证")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sentinel.Secret{
|
||||
SecretId: secretModel.SecretId,
|
||||
AesKey: secretModel.AesKey,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package userproductlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"tianyuan-api/apps/sentinel/internal/model"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateUserProductLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateUserProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateUserProductLogic {
|
||||
return &CreateUserProductLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// UserProduct methods
|
||||
func (l *CreateUserProductLogic) CreateUserProduct(in *sentinel.CreateUserProductRequest) (*sentinel.UserProductEmptyResponse, error) {
|
||||
isExist, err := l.IsUserProductAssociated(l.ctx, in.UserId, in.ProductId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if isExist {
|
||||
return nil, errors.New("该产品已定阅读,无法重复订阅")
|
||||
}
|
||||
_, err = l.svcCtx.UserProductsModel.Insert(l.ctx, &model.UserProducts{UserId: in.UserId, ProductId: in.ProductId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sentinel.UserProductEmptyResponse{}, nil
|
||||
}
|
||||
func (l *CreateUserProductLogic) IsUserProductAssociated(ctx context.Context, userId, productId int64) (bool, error) {
|
||||
_, err := l.svcCtx.UserProductsModel.FindOneUserProduct(ctx, userId, productId)
|
||||
if err != nil {
|
||||
if err == model.ErrNotFound {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package userproductlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/apps/sentinel/client/product"
|
||||
"tianyuan-api/pkg/sqlutil"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetUserProductPageListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetUserProductPageListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserProductPageListLogic {
|
||||
return &GetUserProductPageListLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetUserProductPageListLogic) GetUserProductPageList(in *sentinel.UserProuctPageListRequest) (*sentinel.UserProductResponse, error) {
|
||||
list, total, err := l.svcCtx.UserProductsModel.FindUserProductsList(l.ctx, in.UserId, in.Page, in.PageSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var userProducts []*product.UserProductItem
|
||||
for _, up := range list {
|
||||
userProducts = append(userProducts, &product.UserProductItem{
|
||||
Id: up.Id,
|
||||
ProductId: up.ProductId,
|
||||
ProductName: up.ProductName,
|
||||
ProductPrice: up.ProductPrice,
|
||||
ProductGroup: up.ProductGroup,
|
||||
ProductDescription: sqlutil.NullStringToString(up.ProductDescription),
|
||||
ProductCode: up.ProductCode,
|
||||
CreatedAt: up.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
UpdatedAt: up.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
return &sentinel.UserProductResponse{
|
||||
Total: total,
|
||||
UserProducts: userProducts,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package userproductlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type MatchingUserIdProductCodeLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewMatchingUserIdProductCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MatchingUserIdProductCodeLogic {
|
||||
return &MatchingUserIdProductCodeLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *MatchingUserIdProductCodeLogic) MatchingUserIdProductCode(in *sentinel.MatchingUserIdProductCodeRequest) (*sentinel.MatchResponse, error) {
|
||||
match, err := l.svcCtx.UserProductsModel.FindMatchUserProductCode(l.ctx, in.Id, in.ProductCode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sentinel.MatchResponse{
|
||||
Match: match,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package whitelistlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/apps/sentinel/internal/model"
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateWhitelistLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateWhitelistLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateWhitelistLogic {
|
||||
return &CreateWhitelistLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// Whitelist methods
|
||||
func (l *CreateWhitelistLogic) CreateWhitelist(in *sentinel.CreateWhitelistRequest) (*sentinel.Whitelist, error) {
|
||||
white := model.Whitelist{
|
||||
UserId: in.UserId,
|
||||
WhitelistIp: in.WhitelistIp,
|
||||
}
|
||||
_, err := l.svcCtx.WhitelistModel.Insert(l.ctx, &white)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sentinel.Whitelist{}, nil
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package whitelistlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeleteWhitelistLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDeleteWhitelistLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteWhitelistLogic {
|
||||
return &DeleteWhitelistLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeleteWhitelistLogic) DeleteWhitelist(in *sentinel.DeleteWhitelistRequest) (*sentinel.Whitelist, error) {
|
||||
err := l.svcCtx.WhitelistModel.Delete(l.ctx, in.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sentinel.Whitelist{}, nil
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package whitelistlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetWhitePageListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetWhitePageListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWhitePageListLogic {
|
||||
return &GetWhitePageListLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetWhitePageListLogic) GetWhitePageList(in *sentinel.WhitePageListRequest) (*sentinel.WhitelistResponse, error) {
|
||||
whitelists, total, err := l.svcCtx.WhitelistModel.FindWhitelistList(l.ctx, in.UserId, in.Page, in.PageSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var list []*sentinel.Whitelist
|
||||
for _, w := range whitelists {
|
||||
list = append(list, &sentinel.Whitelist{
|
||||
Id: w.Id,
|
||||
UserId: w.UserId,
|
||||
WhitelistIp: w.WhitelistIp,
|
||||
CreatedAt: w.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
UpdatedAt: w.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
return &sentinel.WhitelistResponse{
|
||||
Total: total,
|
||||
Whitelists: list,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package whitelistlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type MatchWhitelistByIpLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewMatchWhitelistByIpLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MatchWhitelistByIpLogic {
|
||||
return &MatchWhitelistByIpLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *MatchWhitelistByIpLogic) MatchWhitelistByIp(in *sentinel.MatchWhitelistByIpRequest) (*sentinel.MatchResponse, error) {
|
||||
isMatch, err := l.svcCtx.WhitelistModel.IsIpInWhitelist(l.ctx, in.Ip)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sentinel.MatchResponse{
|
||||
Match: isMatch,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package whitelistlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateWhitelistLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateWhitelistLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateWhitelistLogic {
|
||||
return &UpdateWhitelistLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateWhitelistLogic) UpdateWhitelist(in *sentinel.UpdateWhitelistRequest) (*sentinel.Whitelist, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &sentinel.Whitelist{}, nil
|
||||
}
|
||||
53
apps/sentinel/internal/model/productsmodel.go
Normal file
53
apps/sentinel/internal/model/productsmodel.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var _ ProductsModel = (*customProductsModel)(nil)
|
||||
var productsRowsWithoutContent = strings.Join(stringx.Remove(productsFieldNames, "`ProductContent`"), ",")
|
||||
|
||||
type (
|
||||
// ProductsModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customProductsModel.
|
||||
ProductsModel interface {
|
||||
productsModel
|
||||
FindProductsList(ctx context.Context, page, pageSize int64) ([]*Products, int64, error)
|
||||
}
|
||||
|
||||
customProductsModel struct {
|
||||
*defaultProductsModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewProductsModel returns a model for the database table.
|
||||
func NewProductsModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) ProductsModel {
|
||||
return &customProductsModel{
|
||||
defaultProductsModel: newProductsModel(conn, c, opts...),
|
||||
}
|
||||
}
|
||||
func (m *defaultProductsModel) FindProductsList(ctx context.Context, page, pageSize int64) ([]*Products, int64, error) {
|
||||
offset := (page - 1) * pageSize
|
||||
var products []*Products
|
||||
|
||||
query := fmt.Sprintf("SELECT %s FROM %s ORDER BY created_at DESC LIMIT ?,?", productsRowsWithoutContent, m.table)
|
||||
err := m.QueryRowsNoCacheCtx(ctx, &products, query, offset, pageSize)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 查询总数量
|
||||
var total int64
|
||||
countQuery := fmt.Sprintf("SELECT COUNT(*) FROM %s", m.table)
|
||||
err = m.QueryRowNoCacheCtx(ctx, &total, countQuery)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return products, total, nil
|
||||
}
|
||||
153
apps/sentinel/internal/model/productsmodel_gen.go
Normal file
153
apps/sentinel/internal/model/productsmodel_gen.go
Normal file
@@ -0,0 +1,153 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.2
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
productsFieldNames = builder.RawFieldNames(&Products{})
|
||||
productsRows = strings.Join(productsFieldNames, ",")
|
||||
productsRowsExpectAutoSet = strings.Join(stringx.Remove(productsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
productsRowsWithPlaceHolder = strings.Join(stringx.Remove(productsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
|
||||
cacheProductsIdPrefix = "cache:products:id:"
|
||||
cacheProductsProductCodePrefix = "cache:products:productCode:"
|
||||
)
|
||||
|
||||
type (
|
||||
productsModel interface {
|
||||
Insert(ctx context.Context, data *Products) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*Products, error)
|
||||
FindOneByProductCode(ctx context.Context, productCode string) (*Products, error)
|
||||
Update(ctx context.Context, data *Products) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultProductsModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
Products struct {
|
||||
Id int64 `db:"id"` // 产品ID
|
||||
ProductName string `db:"product_name"` // 产品名称
|
||||
ProductCode string `db:"product_code"` // 产品编号
|
||||
ProductDescription sql.NullString `db:"product_description"` // 产品简介
|
||||
ProductContent sql.NullString `db:"product_content"` // 产品内容
|
||||
ProductGroup string `db:"product_group"` // 产品分类
|
||||
ProductPrice float64 `db:"product_price"` // 产品价格
|
||||
CreatedAt time.Time `db:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `db:"updated_at"` // 更新时间
|
||||
}
|
||||
)
|
||||
|
||||
func newProductsModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultProductsModel {
|
||||
return &defaultProductsModel{
|
||||
CachedConn: sqlc.NewConn(conn, c, opts...),
|
||||
table: "`products`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultProductsModel) Delete(ctx context.Context, id int64) error {
|
||||
data, err := m.FindOne(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
productsIdKey := fmt.Sprintf("%s%v", cacheProductsIdPrefix, id)
|
||||
productsProductCodeKey := fmt.Sprintf("%s%v", cacheProductsProductCodePrefix, data.ProductCode)
|
||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, productsIdKey, productsProductCodeKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultProductsModel) FindOne(ctx context.Context, id int64) (*Products, error) {
|
||||
productsIdKey := fmt.Sprintf("%s%v", cacheProductsIdPrefix, id)
|
||||
var resp Products
|
||||
err := m.QueryRowCtx(ctx, &resp, productsIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", productsRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultProductsModel) FindOneByProductCode(ctx context.Context, productCode string) (*Products, error) {
|
||||
productsProductCodeKey := fmt.Sprintf("%s%v", cacheProductsProductCodePrefix, productCode)
|
||||
var resp Products
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, productsProductCodeKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `product_code` = ? limit 1", productsRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, productCode); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Id, nil
|
||||
}, m.queryPrimary)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultProductsModel) Insert(ctx context.Context, data *Products) (sql.Result, error) {
|
||||
productsIdKey := fmt.Sprintf("%s%v", cacheProductsIdPrefix, data.Id)
|
||||
productsProductCodeKey := fmt.Sprintf("%s%v", cacheProductsProductCodePrefix, data.ProductCode)
|
||||
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?)", m.table, productsRowsExpectAutoSet)
|
||||
return conn.ExecCtx(ctx, query, data.ProductName, data.ProductCode, data.ProductDescription, data.ProductContent, data.ProductGroup, data.ProductPrice)
|
||||
}, productsIdKey, productsProductCodeKey)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultProductsModel) Update(ctx context.Context, newData *Products) error {
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
productsIdKey := fmt.Sprintf("%s%v", cacheProductsIdPrefix, data.Id)
|
||||
productsProductCodeKey := fmt.Sprintf("%s%v", cacheProductsProductCodePrefix, data.ProductCode)
|
||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, productsRowsWithPlaceHolder)
|
||||
return conn.ExecCtx(ctx, query, newData.ProductName, newData.ProductCode, newData.ProductDescription, newData.ProductContent, newData.ProductGroup, newData.ProductPrice, newData.Id)
|
||||
}, productsIdKey, productsProductCodeKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultProductsModel) formatPrimary(primary any) string {
|
||||
return fmt.Sprintf("%s%v", cacheProductsIdPrefix, primary)
|
||||
}
|
||||
|
||||
func (m *defaultProductsModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", productsRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary)
|
||||
}
|
||||
|
||||
func (m *defaultProductsModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
27
apps/sentinel/internal/model/secretsmodel.go
Normal file
27
apps/sentinel/internal/model/secretsmodel.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ SecretsModel = (*customSecretsModel)(nil)
|
||||
|
||||
type (
|
||||
// SecretsModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customSecretsModel.
|
||||
SecretsModel interface {
|
||||
secretsModel
|
||||
}
|
||||
|
||||
customSecretsModel struct {
|
||||
*defaultSecretsModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewSecretsModel returns a model for the database table.
|
||||
func NewSecretsModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) SecretsModel {
|
||||
return &customSecretsModel{
|
||||
defaultSecretsModel: newSecretsModel(conn, c, opts...),
|
||||
}
|
||||
}
|
||||
175
apps/sentinel/internal/model/secretsmodel_gen.go
Normal file
175
apps/sentinel/internal/model/secretsmodel_gen.go
Normal file
@@ -0,0 +1,175 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.2
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
secretsFieldNames = builder.RawFieldNames(&Secrets{})
|
||||
secretsRows = strings.Join(secretsFieldNames, ",")
|
||||
secretsRowsExpectAutoSet = strings.Join(stringx.Remove(secretsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
secretsRowsWithPlaceHolder = strings.Join(stringx.Remove(secretsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
|
||||
cacheSecretsIdPrefix = "cache:secrets:id:"
|
||||
cacheSecretsSecretIdPrefix = "cache:secrets:secretId:"
|
||||
cacheSecretsUserIdPrefix = "cache:secrets:userId:"
|
||||
)
|
||||
|
||||
type (
|
||||
secretsModel interface {
|
||||
Insert(ctx context.Context, data *Secrets) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*Secrets, error)
|
||||
FindOneBySecretId(ctx context.Context, secretId string) (*Secrets, error)
|
||||
FindOneByUserId(ctx context.Context, userId int64) (*Secrets, error)
|
||||
Update(ctx context.Context, data *Secrets) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultSecretsModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
Secrets struct {
|
||||
Id int64 `db:"id"` // 密钥ID
|
||||
UserId int64 `db:"user_id"` // 用户ID
|
||||
SecretId string `db:"secret_id"` // 密钥ID
|
||||
AesKey string `db:"aes_key"` // AES 128位密钥
|
||||
CreatedAt time.Time `db:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `db:"updated_at"` // 更新时间
|
||||
}
|
||||
)
|
||||
|
||||
func newSecretsModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultSecretsModel {
|
||||
return &defaultSecretsModel{
|
||||
CachedConn: sqlc.NewConn(conn, c, opts...),
|
||||
table: "`secrets`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultSecretsModel) Delete(ctx context.Context, id int64) error {
|
||||
data, err := m.FindOne(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
secretsIdKey := fmt.Sprintf("%s%v", cacheSecretsIdPrefix, id)
|
||||
secretsSecretIdKey := fmt.Sprintf("%s%v", cacheSecretsSecretIdPrefix, data.SecretId)
|
||||
secretsUserIdKey := fmt.Sprintf("%s%v", cacheSecretsUserIdPrefix, data.UserId)
|
||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, secretsIdKey, secretsSecretIdKey, secretsUserIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultSecretsModel) FindOne(ctx context.Context, id int64) (*Secrets, error) {
|
||||
secretsIdKey := fmt.Sprintf("%s%v", cacheSecretsIdPrefix, id)
|
||||
var resp Secrets
|
||||
err := m.QueryRowCtx(ctx, &resp, secretsIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", secretsRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultSecretsModel) FindOneBySecretId(ctx context.Context, secretId string) (*Secrets, error) {
|
||||
secretsSecretIdKey := fmt.Sprintf("%s%v", cacheSecretsSecretIdPrefix, secretId)
|
||||
var resp Secrets
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, secretsSecretIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `secret_id` = ? limit 1", secretsRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, secretId); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Id, nil
|
||||
}, m.queryPrimary)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultSecretsModel) FindOneByUserId(ctx context.Context, userId int64) (*Secrets, error) {
|
||||
secretsUserIdKey := fmt.Sprintf("%s%v", cacheSecretsUserIdPrefix, userId)
|
||||
var resp Secrets
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, secretsUserIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `user_id` = ? limit 1", secretsRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, userId); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Id, nil
|
||||
}, m.queryPrimary)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultSecretsModel) Insert(ctx context.Context, data *Secrets) (sql.Result, error) {
|
||||
secretsIdKey := fmt.Sprintf("%s%v", cacheSecretsIdPrefix, data.Id)
|
||||
secretsSecretIdKey := fmt.Sprintf("%s%v", cacheSecretsSecretIdPrefix, data.SecretId)
|
||||
secretsUserIdKey := fmt.Sprintf("%s%v", cacheSecretsUserIdPrefix, data.UserId)
|
||||
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?)", m.table, secretsRowsExpectAutoSet)
|
||||
return conn.ExecCtx(ctx, query, data.UserId, data.SecretId, data.AesKey)
|
||||
}, secretsIdKey, secretsSecretIdKey, secretsUserIdKey)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultSecretsModel) Update(ctx context.Context, newData *Secrets) error {
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
secretsIdKey := fmt.Sprintf("%s%v", cacheSecretsIdPrefix, data.Id)
|
||||
secretsSecretIdKey := fmt.Sprintf("%s%v", cacheSecretsSecretIdPrefix, data.SecretId)
|
||||
secretsUserIdKey := fmt.Sprintf("%s%v", cacheSecretsUserIdPrefix, data.UserId)
|
||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, secretsRowsWithPlaceHolder)
|
||||
return conn.ExecCtx(ctx, query, newData.UserId, newData.SecretId, newData.AesKey, newData.Id)
|
||||
}, secretsIdKey, secretsSecretIdKey, secretsUserIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultSecretsModel) formatPrimary(primary any) string {
|
||||
return fmt.Sprintf("%s%v", cacheSecretsIdPrefix, primary)
|
||||
}
|
||||
|
||||
func (m *defaultSecretsModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", secretsRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary)
|
||||
}
|
||||
|
||||
func (m *defaultSecretsModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
154
apps/sentinel/internal/model/userproductsmodel.go
Normal file
154
apps/sentinel/internal/model/userproductsmodel.go
Normal file
@@ -0,0 +1,154 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"time"
|
||||
)
|
||||
|
||||
var _ UserProductsModel = (*customUserProductsModel)(nil)
|
||||
|
||||
type UserProductItem struct {
|
||||
Id int64 `db:"id"`
|
||||
UserId int64 `db:"user_id"`
|
||||
ProductId int64 `db:"product_id"`
|
||||
ProductName string `db:"product_name"`
|
||||
ProductCode string `db:"product_code"`
|
||||
ProductDescription sql.NullString `db:"product_description"`
|
||||
ProductGroup string `db:"product_group"`
|
||||
ProductPrice float64 `db:"product_price"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
type (
|
||||
// UserProductsModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customUserProductsModel.
|
||||
UserProductsModel interface {
|
||||
userProductsModel
|
||||
FindUserProductsList(ctx context.Context, userId, page, pageSize int64) ([]*UserProductItem, int64, error)
|
||||
FindOneUserProduct(ctx context.Context, userId, productId int64) (*UserProducts, error)
|
||||
FindMatchUserProductCode(ctx context.Context, userId int64, productCode string) (bool, error)
|
||||
}
|
||||
|
||||
customUserProductsModel struct {
|
||||
*defaultUserProductsModel
|
||||
rds *redis.Redis
|
||||
}
|
||||
)
|
||||
|
||||
// NewUserProductsModel returns a model for the database table.
|
||||
func NewUserProductsModel(rds *redis.Redis, conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) UserProductsModel {
|
||||
return &customUserProductsModel{
|
||||
rds: rds,
|
||||
defaultUserProductsModel: newUserProductsModel(conn, c, opts...),
|
||||
}
|
||||
}
|
||||
func (m *defaultUserProductsModel) FindUserProductsList(ctx context.Context, userId, page, pageSize int64) ([]*UserProductItem, int64, error) {
|
||||
offset := (page - 1) * pageSize
|
||||
var userProducts []*UserProductItem
|
||||
// SQL查询语句,手动选择需要的products字段
|
||||
query := `
|
||||
SELECT
|
||||
up.id AS user_product_id,
|
||||
up.user_id,
|
||||
p.id AS product_id,
|
||||
p.product_name,
|
||||
p.product_code,
|
||||
COALESCE(p.product_description, '') AS product_description,
|
||||
p.product_group,
|
||||
p.product_price,
|
||||
up.created_at,
|
||||
up.updated_at
|
||||
FROM user_products up
|
||||
JOIN products p ON up.product_id = p.id
|
||||
WHERE up.user_id = ?
|
||||
ORDER BY up.created_at DESC
|
||||
LIMIT ?, ?`
|
||||
|
||||
// 执行查询
|
||||
err := m.QueryRowsNoCacheCtx(ctx, &userProducts, query, userId, offset, pageSize)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 查询总数量
|
||||
var total int64
|
||||
countQuery := "SELECT COUNT(*) FROM user_products WHERE user_id = ?"
|
||||
err = m.QueryRowNoCacheCtx(ctx, &total, countQuery, userId)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return userProducts, total, nil
|
||||
}
|
||||
func (m *customUserProductsModel) FindOneUserProduct(ctx context.Context, userId, productId int64) (*UserProducts, error) {
|
||||
// 定义 Redis 缓存 Set 键
|
||||
redisKey := fmt.Sprintf("user_products:%d", userId)
|
||||
|
||||
// 检查 Redis Set 中是否存在用户与产品的关联
|
||||
isMember, err := m.rds.SismemberCtx(ctx, redisKey, productId)
|
||||
if err == nil && isMember {
|
||||
// 如果 Redis Set 中存在,返回空,因为不需要重复查询
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var userProduct UserProducts
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `user_id` = ? AND `product_id` = ? LIMIT 1", userProductsRows, m.table)
|
||||
err = m.QueryRowNoCacheCtx(ctx, &userProduct, query, userId, productId)
|
||||
switch err {
|
||||
case nil:
|
||||
// 将用户产品的关联写入 Redis Set
|
||||
_, err = m.rds.SaddCtx(ctx, redisKey, productId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &userProduct, nil
|
||||
case sqlc.ErrNotFound:
|
||||
// 返回未找到的错误
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
// 其他错误
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
func (m *customUserProductsModel) FindMatchUserProductCode(ctx context.Context, userId int64, productCode string) (bool, error) {
|
||||
// 定义 Redis 缓存 Set 键
|
||||
redisKey := fmt.Sprintf("user_products:%d", userId)
|
||||
|
||||
// 1. 检查 Redis Set 中是否存在用户与产品的关联
|
||||
isMember, err := m.rds.SismemberCtx(ctx, redisKey, productCode)
|
||||
if err == nil && isMember {
|
||||
// 如果 Redis Set 中存在,表示关联已存在,返回 true
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// 2. 如果 Redis 中没有匹配,则查询数据库
|
||||
query := `
|
||||
SELECT COUNT(*)
|
||||
FROM user_products up
|
||||
JOIN products p ON up.product_id = p.id
|
||||
WHERE up.user_id = ? AND p.product_code = ?`
|
||||
var count int
|
||||
err = m.QueryRowNoCacheCtx(ctx, &count, query, userId, productCode)
|
||||
if err != nil {
|
||||
// 如果数据库查询出错,返回错误
|
||||
return false, err
|
||||
}
|
||||
|
||||
// 3. 如果数据库查询成功且有记录,更新 Redis Set 并返回 true
|
||||
if count > 0 {
|
||||
_, redisErr := m.rds.SaddCtx(ctx, redisKey, productCode)
|
||||
if redisErr != nil {
|
||||
return false, redisErr // Redis 更新失败
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// 4. 如果没有找到匹配的关联,返回 false
|
||||
return false, nil
|
||||
}
|
||||
114
apps/sentinel/internal/model/userproductsmodel_gen.go
Normal file
114
apps/sentinel/internal/model/userproductsmodel_gen.go
Normal file
@@ -0,0 +1,114 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.2
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
userProductsFieldNames = builder.RawFieldNames(&UserProducts{})
|
||||
userProductsRows = strings.Join(userProductsFieldNames, ",")
|
||||
userProductsRowsExpectAutoSet = strings.Join(stringx.Remove(userProductsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
userProductsRowsWithPlaceHolder = strings.Join(stringx.Remove(userProductsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
|
||||
cacheUserProductsIdPrefix = "cache:userProducts:id:"
|
||||
)
|
||||
|
||||
type (
|
||||
userProductsModel interface {
|
||||
Insert(ctx context.Context, data *UserProducts) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*UserProducts, error)
|
||||
Update(ctx context.Context, data *UserProducts) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultUserProductsModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
UserProducts struct {
|
||||
Id int64 `db:"id"` // 用户产品ID
|
||||
UserId int64 `db:"user_id"` // 用户ID
|
||||
ProductId int64 `db:"product_id"` // 产品ID
|
||||
CreatedAt time.Time `db:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `db:"updated_at"` // 更新时间
|
||||
}
|
||||
)
|
||||
|
||||
func newUserProductsModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultUserProductsModel {
|
||||
return &defaultUserProductsModel{
|
||||
CachedConn: sqlc.NewConn(conn, c, opts...),
|
||||
table: "`user_products`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultUserProductsModel) Delete(ctx context.Context, id int64) error {
|
||||
userProductsIdKey := fmt.Sprintf("%s%v", cacheUserProductsIdPrefix, id)
|
||||
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, userProductsIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultUserProductsModel) FindOne(ctx context.Context, id int64) (*UserProducts, error) {
|
||||
userProductsIdKey := fmt.Sprintf("%s%v", cacheUserProductsIdPrefix, id)
|
||||
var resp UserProducts
|
||||
err := m.QueryRowCtx(ctx, &resp, userProductsIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", userProductsRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultUserProductsModel) Insert(ctx context.Context, data *UserProducts) (sql.Result, error) {
|
||||
userProductsIdKey := fmt.Sprintf("%s%v", cacheUserProductsIdPrefix, data.Id)
|
||||
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?)", m.table, userProductsRowsExpectAutoSet)
|
||||
return conn.ExecCtx(ctx, query, data.UserId, data.ProductId)
|
||||
}, userProductsIdKey)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultUserProductsModel) Update(ctx context.Context, data *UserProducts) error {
|
||||
userProductsIdKey := fmt.Sprintf("%s%v", cacheUserProductsIdPrefix, data.Id)
|
||||
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, userProductsRowsWithPlaceHolder)
|
||||
return conn.ExecCtx(ctx, query, data.UserId, data.ProductId, data.Id)
|
||||
}, userProductsIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultUserProductsModel) formatPrimary(primary any) string {
|
||||
return fmt.Sprintf("%s%v", cacheUserProductsIdPrefix, primary)
|
||||
}
|
||||
|
||||
func (m *defaultUserProductsModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", userProductsRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary)
|
||||
}
|
||||
|
||||
func (m *defaultUserProductsModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
5
apps/sentinel/internal/model/vars.go
Normal file
5
apps/sentinel/internal/model/vars.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package model
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var ErrNotFound = sqlx.ErrNotFound
|
||||
87
apps/sentinel/internal/model/whitelistmodel.go
Normal file
87
apps/sentinel/internal/model/whitelistmodel.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ WhitelistModel = (*customWhitelistModel)(nil)
|
||||
|
||||
type (
|
||||
// WhitelistModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customWhitelistModel.
|
||||
WhitelistModel interface {
|
||||
whitelistModel
|
||||
IsIpInWhitelist(ctx context.Context, ip string) (bool, error)
|
||||
FindWhitelistList(ctx context.Context, userId, page, pageSize int64) ([]*Whitelist, int64, error)
|
||||
}
|
||||
|
||||
customWhitelistModel struct {
|
||||
*defaultWhitelistModel
|
||||
rds *redis.Redis
|
||||
}
|
||||
)
|
||||
|
||||
// NewWhitelistModel returns a model for the database table.
|
||||
func NewWhitelistModel(rds *redis.Redis, conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) WhitelistModel {
|
||||
return &customWhitelistModel{
|
||||
rds: rds,
|
||||
defaultWhitelistModel: newWhitelistModel(conn, c, opts...),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customWhitelistModel) IsIpInWhitelist(ctx context.Context, ip string) (bool, error) {
|
||||
// 定义 Redis 缓存 Set 键,存储所有白名单 IP
|
||||
redisKey := "whitelist_ips"
|
||||
|
||||
// 1. 检查 Redis Set 中是否有这个 IP
|
||||
isMember, err := m.rds.SismemberCtx(ctx, redisKey, ip)
|
||||
if err == nil && isMember {
|
||||
// 如果 Redis Set 中存在,表示 IP 已在白名单中
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// 2. 如果 Redis 中没有匹配,查询数据库
|
||||
query := `SELECT whitelist_ip FROM whitelist WHERE whitelist_ip = ? LIMIT 1`
|
||||
var dbIp string
|
||||
err = m.QueryRowNoCacheCtx(ctx, &dbIp, query, ip)
|
||||
if err != nil {
|
||||
// 如果数据库查询出错,返回错误
|
||||
if err == sqlc.ErrNotFound {
|
||||
return false, nil // 如果没有找到,返回 false
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
|
||||
// 3. 如果数据库查询成功,写入 Redis Set,并返回 true
|
||||
_, redisErr := m.rds.SaddCtx(ctx, redisKey, ip)
|
||||
if redisErr != nil {
|
||||
return false, redisErr // Redis 更新失败
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
func (m *customWhitelistModel) FindWhitelistList(ctx context.Context, userId, page, pageSize int64) ([]*Whitelist, int64, error) {
|
||||
offset := (page - 1) * pageSize
|
||||
var whitelist []*Whitelist
|
||||
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE user_id = ? ORDER BY created_at DESC LIMIT ?,?", whitelistRows, m.table)
|
||||
err := m.QueryRowsNoCacheCtx(ctx, &whitelist, query, userId, offset, pageSize)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 查询总数量
|
||||
var total int64
|
||||
countQuery := fmt.Sprintf("SELECT COUNT(*) FROM %s", m.table)
|
||||
err = m.QueryRowNoCacheCtx(ctx, &total, countQuery)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return whitelist, total, nil
|
||||
}
|
||||
114
apps/sentinel/internal/model/whitelistmodel_gen.go
Normal file
114
apps/sentinel/internal/model/whitelistmodel_gen.go
Normal file
@@ -0,0 +1,114 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.2
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
whitelistFieldNames = builder.RawFieldNames(&Whitelist{})
|
||||
whitelistRows = strings.Join(whitelistFieldNames, ",")
|
||||
whitelistRowsExpectAutoSet = strings.Join(stringx.Remove(whitelistFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
whitelistRowsWithPlaceHolder = strings.Join(stringx.Remove(whitelistFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
|
||||
cacheWhitelistIdPrefix = "cache:whitelist:id:"
|
||||
)
|
||||
|
||||
type (
|
||||
whitelistModel interface {
|
||||
Insert(ctx context.Context, data *Whitelist) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*Whitelist, error)
|
||||
Update(ctx context.Context, data *Whitelist) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultWhitelistModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
Whitelist struct {
|
||||
Id int64 `db:"id"` // 白名单ID
|
||||
UserId int64 `db:"user_id"` // 用户ID
|
||||
WhitelistIp string `db:"whitelist_ip"` // 白名单IP
|
||||
CreatedAt time.Time `db:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `db:"updated_at"` // 更新时间
|
||||
}
|
||||
)
|
||||
|
||||
func newWhitelistModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultWhitelistModel {
|
||||
return &defaultWhitelistModel{
|
||||
CachedConn: sqlc.NewConn(conn, c, opts...),
|
||||
table: "`whitelist`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistModel) Delete(ctx context.Context, id int64) error {
|
||||
whitelistIdKey := fmt.Sprintf("%s%v", cacheWhitelistIdPrefix, id)
|
||||
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, whitelistIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistModel) FindOne(ctx context.Context, id int64) (*Whitelist, error) {
|
||||
whitelistIdKey := fmt.Sprintf("%s%v", cacheWhitelistIdPrefix, id)
|
||||
var resp Whitelist
|
||||
err := m.QueryRowCtx(ctx, &resp, whitelistIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", whitelistRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistModel) Insert(ctx context.Context, data *Whitelist) (sql.Result, error) {
|
||||
whitelistIdKey := fmt.Sprintf("%s%v", cacheWhitelistIdPrefix, data.Id)
|
||||
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?)", m.table, whitelistRowsExpectAutoSet)
|
||||
return conn.ExecCtx(ctx, query, data.UserId, data.WhitelistIp)
|
||||
}, whitelistIdKey)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistModel) Update(ctx context.Context, data *Whitelist) error {
|
||||
whitelistIdKey := fmt.Sprintf("%s%v", cacheWhitelistIdPrefix, data.Id)
|
||||
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, whitelistRowsWithPlaceHolder)
|
||||
return conn.ExecCtx(ctx, query, data.UserId, data.WhitelistIp, data.Id)
|
||||
}, whitelistIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistModel) formatPrimary(primary any) string {
|
||||
return fmt.Sprintf("%s%v", cacheWhitelistIdPrefix, primary)
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", whitelistRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary)
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
50
apps/sentinel/internal/server/product/productserver.go
Normal file
50
apps/sentinel/internal/server/product/productserver.go
Normal file
@@ -0,0 +1,50 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.2
|
||||
// Source: sentinel.proto
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/logic/product"
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
)
|
||||
|
||||
type ProductServer struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
sentinel.UnimplementedProductServer
|
||||
}
|
||||
|
||||
func NewProductServer(svcCtx *svc.ServiceContext) *ProductServer {
|
||||
return &ProductServer{
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// Product methods
|
||||
func (s *ProductServer) CreateProduct(ctx context.Context, in *sentinel.CreateProductRequest) (*sentinel.Product, error) {
|
||||
l := productlogic.NewCreateProductLogic(ctx, s.svcCtx)
|
||||
return l.CreateProduct(in)
|
||||
}
|
||||
|
||||
func (s *ProductServer) UpdateProduct(ctx context.Context, in *sentinel.UpdateProductRequest) (*sentinel.Product, error) {
|
||||
l := productlogic.NewUpdateProductLogic(ctx, s.svcCtx)
|
||||
return l.UpdateProduct(in)
|
||||
}
|
||||
|
||||
func (s *ProductServer) DeleteProduct(ctx context.Context, in *sentinel.DeleteProductRequest) (*sentinel.Product, error) {
|
||||
l := productlogic.NewDeleteProductLogic(ctx, s.svcCtx)
|
||||
return l.DeleteProduct(in)
|
||||
}
|
||||
|
||||
func (s *ProductServer) GetProductPageList(ctx context.Context, in *sentinel.PageListRequest) (*sentinel.ProductResponse, error) {
|
||||
l := productlogic.NewGetProductPageListLogic(ctx, s.svcCtx)
|
||||
return l.GetProductPageList(in)
|
||||
}
|
||||
|
||||
func (s *ProductServer) GetProductById(ctx context.Context, in *sentinel.GetRecordByIdRequest) (*sentinel.Product, error) {
|
||||
l := productlogic.NewGetProductByIdLogic(ctx, s.svcCtx)
|
||||
return l.GetProductById(in)
|
||||
}
|
||||
40
apps/sentinel/internal/server/secret/secretserver.go
Normal file
40
apps/sentinel/internal/server/secret/secretserver.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.2
|
||||
// Source: sentinel.proto
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/logic/secret"
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
)
|
||||
|
||||
type SecretServer struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
sentinel.UnimplementedSecretServer
|
||||
}
|
||||
|
||||
func NewSecretServer(svcCtx *svc.ServiceContext) *SecretServer {
|
||||
return &SecretServer{
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// Secret methods
|
||||
func (s *SecretServer) CreateSecret(ctx context.Context, in *sentinel.CreateSecretRequest) (*sentinel.Secret, error) {
|
||||
l := secretlogic.NewCreateSecretLogic(ctx, s.svcCtx)
|
||||
return l.CreateSecret(in)
|
||||
}
|
||||
|
||||
func (s *SecretServer) GetSecretByUserId(ctx context.Context, in *sentinel.GetRecordByIdRequest) (*sentinel.Secret, error) {
|
||||
l := secretlogic.NewGetSecretByUserIdLogic(ctx, s.svcCtx)
|
||||
return l.GetSecretByUserId(in)
|
||||
}
|
||||
|
||||
func (s *SecretServer) GetSecretBySecretId(ctx context.Context, in *sentinel.GetSecretBySecretIdRequest) (*sentinel.Secret, error) {
|
||||
l := secretlogic.NewGetSecretBySecretIdLogic(ctx, s.svcCtx)
|
||||
return l.GetSecretBySecretId(in)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.2
|
||||
// Source: sentinel.proto
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/logic/userproduct"
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
)
|
||||
|
||||
type UserProductServer struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
sentinel.UnimplementedUserProductServer
|
||||
}
|
||||
|
||||
func NewUserProductServer(svcCtx *svc.ServiceContext) *UserProductServer {
|
||||
return &UserProductServer{
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// UserProduct methods
|
||||
func (s *UserProductServer) CreateUserProduct(ctx context.Context, in *sentinel.CreateUserProductRequest) (*sentinel.UserProductEmptyResponse, error) {
|
||||
l := userproductlogic.NewCreateUserProductLogic(ctx, s.svcCtx)
|
||||
return l.CreateUserProduct(in)
|
||||
}
|
||||
|
||||
func (s *UserProductServer) GetUserProductPageList(ctx context.Context, in *sentinel.UserProuctPageListRequest) (*sentinel.UserProductResponse, error) {
|
||||
l := userproductlogic.NewGetUserProductPageListLogic(ctx, s.svcCtx)
|
||||
return l.GetUserProductPageList(in)
|
||||
}
|
||||
|
||||
func (s *UserProductServer) MatchingUserIdProductCode(ctx context.Context, in *sentinel.MatchingUserIdProductCodeRequest) (*sentinel.MatchResponse, error) {
|
||||
l := userproductlogic.NewMatchingUserIdProductCodeLogic(ctx, s.svcCtx)
|
||||
return l.MatchingUserIdProductCode(in)
|
||||
}
|
||||
50
apps/sentinel/internal/server/whitelist/whitelistserver.go
Normal file
50
apps/sentinel/internal/server/whitelist/whitelistserver.go
Normal file
@@ -0,0 +1,50 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.2
|
||||
// Source: sentinel.proto
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/logic/whitelist"
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
)
|
||||
|
||||
type WhitelistServer struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
sentinel.UnimplementedWhitelistServer
|
||||
}
|
||||
|
||||
func NewWhitelistServer(svcCtx *svc.ServiceContext) *WhitelistServer {
|
||||
return &WhitelistServer{
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// Whitelist methods
|
||||
func (s *WhitelistServer) CreateWhitelist(ctx context.Context, in *sentinel.CreateWhitelistRequest) (*sentinel.Whitelist, error) {
|
||||
l := whitelistlogic.NewCreateWhitelistLogic(ctx, s.svcCtx)
|
||||
return l.CreateWhitelist(in)
|
||||
}
|
||||
|
||||
func (s *WhitelistServer) UpdateWhitelist(ctx context.Context, in *sentinel.UpdateWhitelistRequest) (*sentinel.Whitelist, error) {
|
||||
l := whitelistlogic.NewUpdateWhitelistLogic(ctx, s.svcCtx)
|
||||
return l.UpdateWhitelist(in)
|
||||
}
|
||||
|
||||
func (s *WhitelistServer) DeleteWhitelist(ctx context.Context, in *sentinel.DeleteWhitelistRequest) (*sentinel.Whitelist, error) {
|
||||
l := whitelistlogic.NewDeleteWhitelistLogic(ctx, s.svcCtx)
|
||||
return l.DeleteWhitelist(in)
|
||||
}
|
||||
|
||||
func (s *WhitelistServer) GetWhitePageList(ctx context.Context, in *sentinel.WhitePageListRequest) (*sentinel.WhitelistResponse, error) {
|
||||
l := whitelistlogic.NewGetWhitePageListLogic(ctx, s.svcCtx)
|
||||
return l.GetWhitePageList(in)
|
||||
}
|
||||
|
||||
func (s *WhitelistServer) MatchWhitelistByIp(ctx context.Context, in *sentinel.MatchWhitelistByIpRequest) (*sentinel.MatchResponse, error) {
|
||||
l := whitelistlogic.NewMatchWhitelistByIpLogic(ctx, s.svcCtx)
|
||||
return l.MatchWhitelistByIp(in)
|
||||
}
|
||||
36
apps/sentinel/internal/svc/servicecontext.go
Normal file
36
apps/sentinel/internal/svc/servicecontext.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"tianyuan-api/apps/sentinel/internal/config"
|
||||
"tianyuan-api/apps/sentinel/internal/model"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
Redis *redis.Redis
|
||||
WhitelistModel model.WhitelistModel
|
||||
SecretsModel model.SecretsModel
|
||||
ProductsModel model.ProductsModel
|
||||
UserProductsModel model.UserProductsModel
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
db := sqlx.NewMysql(c.DataSource) // 创建数据库连接
|
||||
redisConf := redis.RedisConf{
|
||||
Host: c.CacheRedis[0].Host,
|
||||
Pass: c.CacheRedis[0].Pass,
|
||||
Type: c.CacheRedis[0].Type, // Redis 节点类型,如 "node"
|
||||
}
|
||||
// 使用 MustNewRedis 来初始化 Redis 客户端
|
||||
rds := redis.MustNewRedis(redisConf)
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
Redis: rds,
|
||||
WhitelistModel: model.NewWhitelistModel(rds, db, c.CacheRedis),
|
||||
SecretsModel: model.NewSecretsModel(db, c.CacheRedis),
|
||||
ProductsModel: model.NewProductsModel(db, c.CacheRedis),
|
||||
UserProductsModel: model.NewUserProductsModel(rds, db, c.CacheRedis),
|
||||
}
|
||||
}
|
||||
45
apps/sentinel/sentinel.go
Normal file
45
apps/sentinel/sentinel.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/config"
|
||||
productServer "tianyuan-api/apps/sentinel/internal/server/product"
|
||||
secretServer "tianyuan-api/apps/sentinel/internal/server/secret"
|
||||
userproductServer "tianyuan-api/apps/sentinel/internal/server/userproduct"
|
||||
whitelistServer "tianyuan-api/apps/sentinel/internal/server/whitelist"
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/core/service"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/reflection"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/sentinel.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
ctx := svc.NewServiceContext(c)
|
||||
|
||||
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
||||
sentinel.RegisterWhitelistServer(grpcServer, whitelistServer.NewWhitelistServer(ctx))
|
||||
sentinel.RegisterSecretServer(grpcServer, secretServer.NewSecretServer(ctx))
|
||||
sentinel.RegisterProductServer(grpcServer, productServer.NewProductServer(ctx))
|
||||
sentinel.RegisterUserProductServer(grpcServer, userproductServer.NewUserProductServer(ctx))
|
||||
|
||||
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
||||
reflection.Register(grpcServer)
|
||||
}
|
||||
})
|
||||
defer s.Stop()
|
||||
|
||||
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
|
||||
s.Start()
|
||||
}
|
||||
195
apps/sentinel/sentinel.proto
Normal file
195
apps/sentinel/sentinel.proto
Normal file
@@ -0,0 +1,195 @@
|
||||
syntax = "proto3";
|
||||
|
||||
|
||||
option go_package = "./sentinel";
|
||||
|
||||
message PageListRequest {
|
||||
int64 page = 2;
|
||||
int64 page_size = 3;
|
||||
}
|
||||
message UserProuctPageListRequest {
|
||||
int64 user_id = 1;
|
||||
int64 page = 2;
|
||||
int64 page_size = 3;
|
||||
}
|
||||
message WhitePageListRequest {
|
||||
int64 user_id = 1;
|
||||
int64 page = 2;
|
||||
int64 page_size = 3;
|
||||
}
|
||||
|
||||
message GetRecordByIdRequest {
|
||||
int64 id = 1;
|
||||
}
|
||||
|
||||
|
||||
message Whitelist {
|
||||
int64 id = 1;
|
||||
int64 user_id = 2;
|
||||
string whitelist_ip = 3;
|
||||
string created_at = 4;
|
||||
string updated_at = 5;
|
||||
}
|
||||
|
||||
message CreateWhitelistRequest {
|
||||
int64 user_id = 1;
|
||||
string whitelist_ip = 2;
|
||||
}
|
||||
|
||||
message UpdateWhitelistRequest {
|
||||
int64 id = 1;
|
||||
string whitelist_ip = 2;
|
||||
}
|
||||
|
||||
message DeleteWhitelistRequest {
|
||||
int64 id = 1;
|
||||
}
|
||||
|
||||
message WhitelistResponse {
|
||||
int64 total = 1;
|
||||
repeated Whitelist whitelists = 2;
|
||||
}
|
||||
|
||||
// Message for Secrets operations
|
||||
message Secret {
|
||||
int64 id = 1;
|
||||
int64 user_id = 2;
|
||||
string secret_id = 3;
|
||||
string aes_key = 4;
|
||||
string created_at = 5;
|
||||
string updated_at = 6;
|
||||
}
|
||||
message GetSecretBySecretIdRequest {
|
||||
string secret_id = 1;
|
||||
}
|
||||
message CreateSecretRequest {
|
||||
int64 user_id = 1;
|
||||
}
|
||||
|
||||
message UpdateSecretRequest {
|
||||
int64 id = 1;
|
||||
string secret_id = 2;
|
||||
string aes_key = 3;
|
||||
}
|
||||
|
||||
message DeleteSecretRequest {
|
||||
int64 id = 1;
|
||||
}
|
||||
|
||||
message SecretResponse {
|
||||
int64 total = 1;
|
||||
repeated Secret secrets = 2;
|
||||
}
|
||||
|
||||
// Message for Products operations
|
||||
message Product {
|
||||
int64 id = 1;
|
||||
string product_name = 2;
|
||||
string product_code = 3;
|
||||
string product_description = 4;
|
||||
string product_content = 5;
|
||||
string product_group = 6;
|
||||
double product_price = 7;
|
||||
string created_at = 8;
|
||||
string updated_at = 9;
|
||||
}
|
||||
|
||||
message CreateProductRequest {
|
||||
string product_name = 1;
|
||||
string product_code = 2;
|
||||
string product_description = 3;
|
||||
string product_group = 4;
|
||||
string product_content = 5;
|
||||
double product_price = 6;
|
||||
}
|
||||
|
||||
message UpdateProductRequest {
|
||||
int64 id = 1;
|
||||
string product_name = 2;
|
||||
string product_code = 3;
|
||||
string product_description = 4;
|
||||
string product_content = 5;
|
||||
string product_group = 6;
|
||||
double product_price = 7;
|
||||
}
|
||||
|
||||
message DeleteProductRequest {
|
||||
int64 id = 1;
|
||||
}
|
||||
|
||||
message ProductResponse {
|
||||
int64 total = 1;
|
||||
repeated Product products = 2;
|
||||
}
|
||||
|
||||
// Message for UserProducts operations
|
||||
message UserProductEmptyResponse {
|
||||
}
|
||||
message UserProductItem {
|
||||
int64 id = 1; // 用户产品ID
|
||||
int64 productId = 2; // 产品ID
|
||||
string productName = 3; // 产品名称
|
||||
string productCode = 4; // 产品编号
|
||||
string productDescription = 5; // 产品简介
|
||||
string productGroup = 6; // 产品分类
|
||||
double productPrice = 7; // 产品价格
|
||||
string createdAt = 8; // 创建时间
|
||||
string updatedAt = 9; // 更新时间
|
||||
}
|
||||
message CreateUserProductRequest {
|
||||
int64 user_id = 1;
|
||||
int64 product_id = 2;
|
||||
}
|
||||
|
||||
message UpdateUserProductRequest {
|
||||
int64 id = 1;
|
||||
}
|
||||
|
||||
message DeleteUserProductRequest {
|
||||
int64 id = 1;
|
||||
}
|
||||
|
||||
message UserProductResponse {
|
||||
int64 total = 1;
|
||||
repeated UserProductItem user_products = 2;
|
||||
}
|
||||
|
||||
message matchingUserIdProductCodeRequest {
|
||||
int64 id = 1;
|
||||
string product_code = 2;
|
||||
}
|
||||
message matchResponse {
|
||||
bool match = 1;
|
||||
}
|
||||
message MatchWhitelistByIpRequest{
|
||||
string ip = 1;
|
||||
}
|
||||
// Service definitions for Whitelist, Secrets, Products, and UserProducts
|
||||
service whitelist {
|
||||
// Whitelist methods
|
||||
rpc CreateWhitelist(CreateWhitelistRequest) returns (Whitelist);
|
||||
rpc UpdateWhitelist(UpdateWhitelistRequest) returns (Whitelist);
|
||||
rpc DeleteWhitelist(DeleteWhitelistRequest) returns (Whitelist);
|
||||
rpc GetWhitePageList(WhitePageListRequest) returns (WhitelistResponse);
|
||||
rpc MatchWhitelistByIp(MatchWhitelistByIpRequest) returns (matchResponse);
|
||||
}
|
||||
service secret {
|
||||
// Secret methods
|
||||
rpc CreateSecret(CreateSecretRequest) returns (Secret);
|
||||
rpc GetSecretByUserId(GetRecordByIdRequest) returns (Secret);
|
||||
rpc GetSecretBySecretId(GetSecretBySecretIdRequest) returns (Secret);
|
||||
}
|
||||
service product {
|
||||
// Product methods
|
||||
rpc CreateProduct(CreateProductRequest) returns (Product);
|
||||
rpc UpdateProduct(UpdateProductRequest) returns (Product);
|
||||
rpc DeleteProduct(DeleteProductRequest) returns (Product);
|
||||
rpc GetProductPageList(PageListRequest) returns (ProductResponse);
|
||||
rpc GetProductById(GetRecordByIdRequest) returns (Product);
|
||||
}
|
||||
service userProduct {
|
||||
// UserProduct methods
|
||||
rpc CreateUserProduct(CreateUserProductRequest) returns (UserProductEmptyResponse);
|
||||
rpc GetUserProductPageList(UserProuctPageListRequest) returns (UserProductResponse);
|
||||
rpc MatchingUserIdProductCode(matchingUserIdProductCodeRequest) returns (matchResponse);
|
||||
}
|
||||
40
apps/sentinel/sentinel.sql
Normal file
40
apps/sentinel/sentinel.sql
Normal file
@@ -0,0 +1,40 @@
|
||||
CREATE TABLE `whitelist` (
|
||||
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '白名单ID',
|
||||
`user_id` INT(11) NOT NULL COMMENT '用户ID',
|
||||
`whitelist_ip` VARCHAR(255) NOT NULL COMMENT '白名单IP',
|
||||
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='白名单表,存储用户的IP白名单';
|
||||
|
||||
CREATE TABLE `secrets` (
|
||||
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '密钥ID',
|
||||
`user_id` INT(11) NOT NULL UNIQUE COMMENT '用户ID',
|
||||
`secret_id` VARCHAR(64) NOT NULL UNIQUE COMMENT '密钥ID',
|
||||
`aes_key` VARCHAR(32) NOT NULL COMMENT 'AES 128位密钥',
|
||||
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='密钥表,存储用户的密钥信息';
|
||||
|
||||
CREATE TABLE `products` (
|
||||
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '产品ID',
|
||||
`product_name` VARCHAR(255) NOT NULL COMMENT '产品名称',
|
||||
`product_code` VARCHAR(64) NOT NULL UNIQUE COMMENT '产品编号',
|
||||
`product_description` TEXT COMMENT '产品简介',
|
||||
`product_content` TEXT COMMENT '产品内容',
|
||||
`product_group` VARCHAR(32) NOT NULL COMMENT '产品分类',
|
||||
`product_price` DECIMAL(10, 2) NOT NULL COMMENT '产品价格',
|
||||
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='产品表,存储产品的详细信息';
|
||||
|
||||
CREATE TABLE `user_products` (
|
||||
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '用户产品ID',
|
||||
`user_id` INT(11) NOT NULL COMMENT '用户ID',
|
||||
`product_id` INT(11) NOT NULL COMMENT '产品ID',
|
||||
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户产品表,存储用户开通的产品记录';
|
||||
2507
apps/sentinel/sentinel/sentinel.pb.go
Normal file
2507
apps/sentinel/sentinel/sentinel.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
851
apps/sentinel/sentinel/sentinel_grpc.pb.go
Normal file
851
apps/sentinel/sentinel/sentinel_grpc.pb.go
Normal file
@@ -0,0 +1,851 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.4.0
|
||||
// - protoc v3.19.4
|
||||
// source: sentinel.proto
|
||||
|
||||
package sentinel
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.62.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion8
|
||||
|
||||
const (
|
||||
Whitelist_CreateWhitelist_FullMethodName = "/whitelist/CreateWhitelist"
|
||||
Whitelist_UpdateWhitelist_FullMethodName = "/whitelist/UpdateWhitelist"
|
||||
Whitelist_DeleteWhitelist_FullMethodName = "/whitelist/DeleteWhitelist"
|
||||
Whitelist_GetWhitePageList_FullMethodName = "/whitelist/GetWhitePageList"
|
||||
Whitelist_MatchWhitelistByIp_FullMethodName = "/whitelist/MatchWhitelistByIp"
|
||||
)
|
||||
|
||||
// WhitelistClient is the client API for Whitelist service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
//
|
||||
// Service definitions for Whitelist, Secrets, Products, and UserProducts
|
||||
type WhitelistClient interface {
|
||||
// Whitelist methods
|
||||
CreateWhitelist(ctx context.Context, in *CreateWhitelistRequest, opts ...grpc.CallOption) (*Whitelist, error)
|
||||
UpdateWhitelist(ctx context.Context, in *UpdateWhitelistRequest, opts ...grpc.CallOption) (*Whitelist, error)
|
||||
DeleteWhitelist(ctx context.Context, in *DeleteWhitelistRequest, opts ...grpc.CallOption) (*Whitelist, error)
|
||||
GetWhitePageList(ctx context.Context, in *WhitePageListRequest, opts ...grpc.CallOption) (*WhitelistResponse, error)
|
||||
MatchWhitelistByIp(ctx context.Context, in *MatchWhitelistByIpRequest, opts ...grpc.CallOption) (*MatchResponse, error)
|
||||
}
|
||||
|
||||
type whitelistClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewWhitelistClient(cc grpc.ClientConnInterface) WhitelistClient {
|
||||
return &whitelistClient{cc}
|
||||
}
|
||||
|
||||
func (c *whitelistClient) CreateWhitelist(ctx context.Context, in *CreateWhitelistRequest, opts ...grpc.CallOption) (*Whitelist, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Whitelist)
|
||||
err := c.cc.Invoke(ctx, Whitelist_CreateWhitelist_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *whitelistClient) UpdateWhitelist(ctx context.Context, in *UpdateWhitelistRequest, opts ...grpc.CallOption) (*Whitelist, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Whitelist)
|
||||
err := c.cc.Invoke(ctx, Whitelist_UpdateWhitelist_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *whitelistClient) DeleteWhitelist(ctx context.Context, in *DeleteWhitelistRequest, opts ...grpc.CallOption) (*Whitelist, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Whitelist)
|
||||
err := c.cc.Invoke(ctx, Whitelist_DeleteWhitelist_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *whitelistClient) GetWhitePageList(ctx context.Context, in *WhitePageListRequest, opts ...grpc.CallOption) (*WhitelistResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(WhitelistResponse)
|
||||
err := c.cc.Invoke(ctx, Whitelist_GetWhitePageList_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *whitelistClient) MatchWhitelistByIp(ctx context.Context, in *MatchWhitelistByIpRequest, opts ...grpc.CallOption) (*MatchResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(MatchResponse)
|
||||
err := c.cc.Invoke(ctx, Whitelist_MatchWhitelistByIp_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// WhitelistServer is the server API for Whitelist service.
|
||||
// All implementations must embed UnimplementedWhitelistServer
|
||||
// for forward compatibility
|
||||
//
|
||||
// Service definitions for Whitelist, Secrets, Products, and UserProducts
|
||||
type WhitelistServer interface {
|
||||
// Whitelist methods
|
||||
CreateWhitelist(context.Context, *CreateWhitelistRequest) (*Whitelist, error)
|
||||
UpdateWhitelist(context.Context, *UpdateWhitelistRequest) (*Whitelist, error)
|
||||
DeleteWhitelist(context.Context, *DeleteWhitelistRequest) (*Whitelist, error)
|
||||
GetWhitePageList(context.Context, *WhitePageListRequest) (*WhitelistResponse, error)
|
||||
MatchWhitelistByIp(context.Context, *MatchWhitelistByIpRequest) (*MatchResponse, error)
|
||||
mustEmbedUnimplementedWhitelistServer()
|
||||
}
|
||||
|
||||
// UnimplementedWhitelistServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedWhitelistServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedWhitelistServer) CreateWhitelist(context.Context, *CreateWhitelistRequest) (*Whitelist, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateWhitelist not implemented")
|
||||
}
|
||||
func (UnimplementedWhitelistServer) UpdateWhitelist(context.Context, *UpdateWhitelistRequest) (*Whitelist, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method UpdateWhitelist not implemented")
|
||||
}
|
||||
func (UnimplementedWhitelistServer) DeleteWhitelist(context.Context, *DeleteWhitelistRequest) (*Whitelist, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DeleteWhitelist not implemented")
|
||||
}
|
||||
func (UnimplementedWhitelistServer) GetWhitePageList(context.Context, *WhitePageListRequest) (*WhitelistResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetWhitePageList not implemented")
|
||||
}
|
||||
func (UnimplementedWhitelistServer) MatchWhitelistByIp(context.Context, *MatchWhitelistByIpRequest) (*MatchResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method MatchWhitelistByIp not implemented")
|
||||
}
|
||||
func (UnimplementedWhitelistServer) mustEmbedUnimplementedWhitelistServer() {}
|
||||
|
||||
// UnsafeWhitelistServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to WhitelistServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeWhitelistServer interface {
|
||||
mustEmbedUnimplementedWhitelistServer()
|
||||
}
|
||||
|
||||
func RegisterWhitelistServer(s grpc.ServiceRegistrar, srv WhitelistServer) {
|
||||
s.RegisterService(&Whitelist_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _Whitelist_CreateWhitelist_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CreateWhitelistRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(WhitelistServer).CreateWhitelist(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Whitelist_CreateWhitelist_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(WhitelistServer).CreateWhitelist(ctx, req.(*CreateWhitelistRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Whitelist_UpdateWhitelist_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UpdateWhitelistRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(WhitelistServer).UpdateWhitelist(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Whitelist_UpdateWhitelist_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(WhitelistServer).UpdateWhitelist(ctx, req.(*UpdateWhitelistRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Whitelist_DeleteWhitelist_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DeleteWhitelistRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(WhitelistServer).DeleteWhitelist(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Whitelist_DeleteWhitelist_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(WhitelistServer).DeleteWhitelist(ctx, req.(*DeleteWhitelistRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Whitelist_GetWhitePageList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(WhitePageListRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(WhitelistServer).GetWhitePageList(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Whitelist_GetWhitePageList_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(WhitelistServer).GetWhitePageList(ctx, req.(*WhitePageListRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Whitelist_MatchWhitelistByIp_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(MatchWhitelistByIpRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(WhitelistServer).MatchWhitelistByIp(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Whitelist_MatchWhitelistByIp_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(WhitelistServer).MatchWhitelistByIp(ctx, req.(*MatchWhitelistByIpRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// Whitelist_ServiceDesc is the grpc.ServiceDesc for Whitelist service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var Whitelist_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "whitelist",
|
||||
HandlerType: (*WhitelistServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "CreateWhitelist",
|
||||
Handler: _Whitelist_CreateWhitelist_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "UpdateWhitelist",
|
||||
Handler: _Whitelist_UpdateWhitelist_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DeleteWhitelist",
|
||||
Handler: _Whitelist_DeleteWhitelist_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetWhitePageList",
|
||||
Handler: _Whitelist_GetWhitePageList_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "MatchWhitelistByIp",
|
||||
Handler: _Whitelist_MatchWhitelistByIp_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "sentinel.proto",
|
||||
}
|
||||
|
||||
const (
|
||||
Secret_CreateSecret_FullMethodName = "/secret/CreateSecret"
|
||||
Secret_GetSecretByUserId_FullMethodName = "/secret/GetSecretByUserId"
|
||||
Secret_GetSecretBySecretId_FullMethodName = "/secret/GetSecretBySecretId"
|
||||
)
|
||||
|
||||
// SecretClient is the client API for Secret service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type SecretClient interface {
|
||||
// Secret methods
|
||||
CreateSecret(ctx context.Context, in *CreateSecretRequest, opts ...grpc.CallOption) (*Secret, error)
|
||||
GetSecretByUserId(ctx context.Context, in *GetRecordByIdRequest, opts ...grpc.CallOption) (*Secret, error)
|
||||
GetSecretBySecretId(ctx context.Context, in *GetSecretBySecretIdRequest, opts ...grpc.CallOption) (*Secret, error)
|
||||
}
|
||||
|
||||
type secretClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewSecretClient(cc grpc.ClientConnInterface) SecretClient {
|
||||
return &secretClient{cc}
|
||||
}
|
||||
|
||||
func (c *secretClient) CreateSecret(ctx context.Context, in *CreateSecretRequest, opts ...grpc.CallOption) (*Secret, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Secret)
|
||||
err := c.cc.Invoke(ctx, Secret_CreateSecret_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *secretClient) GetSecretByUserId(ctx context.Context, in *GetRecordByIdRequest, opts ...grpc.CallOption) (*Secret, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Secret)
|
||||
err := c.cc.Invoke(ctx, Secret_GetSecretByUserId_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *secretClient) GetSecretBySecretId(ctx context.Context, in *GetSecretBySecretIdRequest, opts ...grpc.CallOption) (*Secret, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Secret)
|
||||
err := c.cc.Invoke(ctx, Secret_GetSecretBySecretId_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// SecretServer is the server API for Secret service.
|
||||
// All implementations must embed UnimplementedSecretServer
|
||||
// for forward compatibility
|
||||
type SecretServer interface {
|
||||
// Secret methods
|
||||
CreateSecret(context.Context, *CreateSecretRequest) (*Secret, error)
|
||||
GetSecretByUserId(context.Context, *GetRecordByIdRequest) (*Secret, error)
|
||||
GetSecretBySecretId(context.Context, *GetSecretBySecretIdRequest) (*Secret, error)
|
||||
mustEmbedUnimplementedSecretServer()
|
||||
}
|
||||
|
||||
// UnimplementedSecretServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedSecretServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedSecretServer) CreateSecret(context.Context, *CreateSecretRequest) (*Secret, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateSecret not implemented")
|
||||
}
|
||||
func (UnimplementedSecretServer) GetSecretByUserId(context.Context, *GetRecordByIdRequest) (*Secret, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetSecretByUserId not implemented")
|
||||
}
|
||||
func (UnimplementedSecretServer) GetSecretBySecretId(context.Context, *GetSecretBySecretIdRequest) (*Secret, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetSecretBySecretId not implemented")
|
||||
}
|
||||
func (UnimplementedSecretServer) mustEmbedUnimplementedSecretServer() {}
|
||||
|
||||
// UnsafeSecretServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to SecretServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeSecretServer interface {
|
||||
mustEmbedUnimplementedSecretServer()
|
||||
}
|
||||
|
||||
func RegisterSecretServer(s grpc.ServiceRegistrar, srv SecretServer) {
|
||||
s.RegisterService(&Secret_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _Secret_CreateSecret_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CreateSecretRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SecretServer).CreateSecret(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Secret_CreateSecret_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SecretServer).CreateSecret(ctx, req.(*CreateSecretRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Secret_GetSecretByUserId_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetRecordByIdRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SecretServer).GetSecretByUserId(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Secret_GetSecretByUserId_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SecretServer).GetSecretByUserId(ctx, req.(*GetRecordByIdRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Secret_GetSecretBySecretId_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetSecretBySecretIdRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SecretServer).GetSecretBySecretId(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Secret_GetSecretBySecretId_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SecretServer).GetSecretBySecretId(ctx, req.(*GetSecretBySecretIdRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// Secret_ServiceDesc is the grpc.ServiceDesc for Secret service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var Secret_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "secret",
|
||||
HandlerType: (*SecretServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "CreateSecret",
|
||||
Handler: _Secret_CreateSecret_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetSecretByUserId",
|
||||
Handler: _Secret_GetSecretByUserId_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetSecretBySecretId",
|
||||
Handler: _Secret_GetSecretBySecretId_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "sentinel.proto",
|
||||
}
|
||||
|
||||
const (
|
||||
Product_CreateProduct_FullMethodName = "/product/CreateProduct"
|
||||
Product_UpdateProduct_FullMethodName = "/product/UpdateProduct"
|
||||
Product_DeleteProduct_FullMethodName = "/product/DeleteProduct"
|
||||
Product_GetProductPageList_FullMethodName = "/product/GetProductPageList"
|
||||
Product_GetProductById_FullMethodName = "/product/GetProductById"
|
||||
)
|
||||
|
||||
// ProductClient is the client API for Product service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type ProductClient interface {
|
||||
// Product methods
|
||||
CreateProduct(ctx context.Context, in *CreateProductRequest, opts ...grpc.CallOption) (*Product, error)
|
||||
UpdateProduct(ctx context.Context, in *UpdateProductRequest, opts ...grpc.CallOption) (*Product, error)
|
||||
DeleteProduct(ctx context.Context, in *DeleteProductRequest, opts ...grpc.CallOption) (*Product, error)
|
||||
GetProductPageList(ctx context.Context, in *PageListRequest, opts ...grpc.CallOption) (*ProductResponse, error)
|
||||
GetProductById(ctx context.Context, in *GetRecordByIdRequest, opts ...grpc.CallOption) (*Product, error)
|
||||
}
|
||||
|
||||
type productClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewProductClient(cc grpc.ClientConnInterface) ProductClient {
|
||||
return &productClient{cc}
|
||||
}
|
||||
|
||||
func (c *productClient) CreateProduct(ctx context.Context, in *CreateProductRequest, opts ...grpc.CallOption) (*Product, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Product)
|
||||
err := c.cc.Invoke(ctx, Product_CreateProduct_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *productClient) UpdateProduct(ctx context.Context, in *UpdateProductRequest, opts ...grpc.CallOption) (*Product, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Product)
|
||||
err := c.cc.Invoke(ctx, Product_UpdateProduct_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *productClient) DeleteProduct(ctx context.Context, in *DeleteProductRequest, opts ...grpc.CallOption) (*Product, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Product)
|
||||
err := c.cc.Invoke(ctx, Product_DeleteProduct_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *productClient) GetProductPageList(ctx context.Context, in *PageListRequest, opts ...grpc.CallOption) (*ProductResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(ProductResponse)
|
||||
err := c.cc.Invoke(ctx, Product_GetProductPageList_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *productClient) GetProductById(ctx context.Context, in *GetRecordByIdRequest, opts ...grpc.CallOption) (*Product, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Product)
|
||||
err := c.cc.Invoke(ctx, Product_GetProductById_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ProductServer is the server API for Product service.
|
||||
// All implementations must embed UnimplementedProductServer
|
||||
// for forward compatibility
|
||||
type ProductServer interface {
|
||||
// Product methods
|
||||
CreateProduct(context.Context, *CreateProductRequest) (*Product, error)
|
||||
UpdateProduct(context.Context, *UpdateProductRequest) (*Product, error)
|
||||
DeleteProduct(context.Context, *DeleteProductRequest) (*Product, error)
|
||||
GetProductPageList(context.Context, *PageListRequest) (*ProductResponse, error)
|
||||
GetProductById(context.Context, *GetRecordByIdRequest) (*Product, error)
|
||||
mustEmbedUnimplementedProductServer()
|
||||
}
|
||||
|
||||
// UnimplementedProductServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedProductServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedProductServer) CreateProduct(context.Context, *CreateProductRequest) (*Product, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateProduct not implemented")
|
||||
}
|
||||
func (UnimplementedProductServer) UpdateProduct(context.Context, *UpdateProductRequest) (*Product, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method UpdateProduct not implemented")
|
||||
}
|
||||
func (UnimplementedProductServer) DeleteProduct(context.Context, *DeleteProductRequest) (*Product, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DeleteProduct not implemented")
|
||||
}
|
||||
func (UnimplementedProductServer) GetProductPageList(context.Context, *PageListRequest) (*ProductResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetProductPageList not implemented")
|
||||
}
|
||||
func (UnimplementedProductServer) GetProductById(context.Context, *GetRecordByIdRequest) (*Product, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetProductById not implemented")
|
||||
}
|
||||
func (UnimplementedProductServer) mustEmbedUnimplementedProductServer() {}
|
||||
|
||||
// UnsafeProductServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to ProductServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeProductServer interface {
|
||||
mustEmbedUnimplementedProductServer()
|
||||
}
|
||||
|
||||
func RegisterProductServer(s grpc.ServiceRegistrar, srv ProductServer) {
|
||||
s.RegisterService(&Product_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _Product_CreateProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CreateProductRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ProductServer).CreateProduct(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Product_CreateProduct_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ProductServer).CreateProduct(ctx, req.(*CreateProductRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Product_UpdateProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UpdateProductRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ProductServer).UpdateProduct(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Product_UpdateProduct_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ProductServer).UpdateProduct(ctx, req.(*UpdateProductRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Product_DeleteProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DeleteProductRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ProductServer).DeleteProduct(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Product_DeleteProduct_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ProductServer).DeleteProduct(ctx, req.(*DeleteProductRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Product_GetProductPageList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(PageListRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ProductServer).GetProductPageList(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Product_GetProductPageList_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ProductServer).GetProductPageList(ctx, req.(*PageListRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Product_GetProductById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetRecordByIdRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ProductServer).GetProductById(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Product_GetProductById_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ProductServer).GetProductById(ctx, req.(*GetRecordByIdRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// Product_ServiceDesc is the grpc.ServiceDesc for Product service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var Product_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "product",
|
||||
HandlerType: (*ProductServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "CreateProduct",
|
||||
Handler: _Product_CreateProduct_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "UpdateProduct",
|
||||
Handler: _Product_UpdateProduct_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DeleteProduct",
|
||||
Handler: _Product_DeleteProduct_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetProductPageList",
|
||||
Handler: _Product_GetProductPageList_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetProductById",
|
||||
Handler: _Product_GetProductById_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "sentinel.proto",
|
||||
}
|
||||
|
||||
const (
|
||||
UserProduct_CreateUserProduct_FullMethodName = "/userProduct/CreateUserProduct"
|
||||
UserProduct_GetUserProductPageList_FullMethodName = "/userProduct/GetUserProductPageList"
|
||||
UserProduct_MatchingUserIdProductCode_FullMethodName = "/userProduct/MatchingUserIdProductCode"
|
||||
)
|
||||
|
||||
// UserProductClient is the client API for UserProduct service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type UserProductClient interface {
|
||||
// UserProduct methods
|
||||
CreateUserProduct(ctx context.Context, in *CreateUserProductRequest, opts ...grpc.CallOption) (*UserProductEmptyResponse, error)
|
||||
GetUserProductPageList(ctx context.Context, in *UserProuctPageListRequest, opts ...grpc.CallOption) (*UserProductResponse, error)
|
||||
MatchingUserIdProductCode(ctx context.Context, in *MatchingUserIdProductCodeRequest, opts ...grpc.CallOption) (*MatchResponse, error)
|
||||
}
|
||||
|
||||
type userProductClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewUserProductClient(cc grpc.ClientConnInterface) UserProductClient {
|
||||
return &userProductClient{cc}
|
||||
}
|
||||
|
||||
func (c *userProductClient) CreateUserProduct(ctx context.Context, in *CreateUserProductRequest, opts ...grpc.CallOption) (*UserProductEmptyResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(UserProductEmptyResponse)
|
||||
err := c.cc.Invoke(ctx, UserProduct_CreateUserProduct_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *userProductClient) GetUserProductPageList(ctx context.Context, in *UserProuctPageListRequest, opts ...grpc.CallOption) (*UserProductResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(UserProductResponse)
|
||||
err := c.cc.Invoke(ctx, UserProduct_GetUserProductPageList_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *userProductClient) MatchingUserIdProductCode(ctx context.Context, in *MatchingUserIdProductCodeRequest, opts ...grpc.CallOption) (*MatchResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(MatchResponse)
|
||||
err := c.cc.Invoke(ctx, UserProduct_MatchingUserIdProductCode_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// UserProductServer is the server API for UserProduct service.
|
||||
// All implementations must embed UnimplementedUserProductServer
|
||||
// for forward compatibility
|
||||
type UserProductServer interface {
|
||||
// UserProduct methods
|
||||
CreateUserProduct(context.Context, *CreateUserProductRequest) (*UserProductEmptyResponse, error)
|
||||
GetUserProductPageList(context.Context, *UserProuctPageListRequest) (*UserProductResponse, error)
|
||||
MatchingUserIdProductCode(context.Context, *MatchingUserIdProductCodeRequest) (*MatchResponse, error)
|
||||
mustEmbedUnimplementedUserProductServer()
|
||||
}
|
||||
|
||||
// UnimplementedUserProductServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedUserProductServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedUserProductServer) CreateUserProduct(context.Context, *CreateUserProductRequest) (*UserProductEmptyResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateUserProduct not implemented")
|
||||
}
|
||||
func (UnimplementedUserProductServer) GetUserProductPageList(context.Context, *UserProuctPageListRequest) (*UserProductResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetUserProductPageList not implemented")
|
||||
}
|
||||
func (UnimplementedUserProductServer) MatchingUserIdProductCode(context.Context, *MatchingUserIdProductCodeRequest) (*MatchResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method MatchingUserIdProductCode not implemented")
|
||||
}
|
||||
func (UnimplementedUserProductServer) mustEmbedUnimplementedUserProductServer() {}
|
||||
|
||||
// UnsafeUserProductServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to UserProductServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeUserProductServer interface {
|
||||
mustEmbedUnimplementedUserProductServer()
|
||||
}
|
||||
|
||||
func RegisterUserProductServer(s grpc.ServiceRegistrar, srv UserProductServer) {
|
||||
s.RegisterService(&UserProduct_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _UserProduct_CreateUserProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CreateUserProductRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UserProductServer).CreateUserProduct(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: UserProduct_CreateUserProduct_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UserProductServer).CreateUserProduct(ctx, req.(*CreateUserProductRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _UserProduct_GetUserProductPageList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UserProuctPageListRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UserProductServer).GetUserProductPageList(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: UserProduct_GetUserProductPageList_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UserProductServer).GetUserProductPageList(ctx, req.(*UserProuctPageListRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _UserProduct_MatchingUserIdProductCode_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(MatchingUserIdProductCodeRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UserProductServer).MatchingUserIdProductCode(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: UserProduct_MatchingUserIdProductCode_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UserProductServer).MatchingUserIdProductCode(ctx, req.(*MatchingUserIdProductCodeRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// UserProduct_ServiceDesc is the grpc.ServiceDesc for UserProduct service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var UserProduct_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "userProduct",
|
||||
HandlerType: (*UserProductServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "CreateUserProduct",
|
||||
Handler: _UserProduct_CreateUserProduct_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetUserProductPageList",
|
||||
Handler: _UserProduct_GetUserProductPageList_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "MatchingUserIdProductCode",
|
||||
Handler: _UserProduct_MatchingUserIdProductCode_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "sentinel.proto",
|
||||
}
|
||||
Reference in New Issue
Block a user