first commit
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user