39 lines
881 B
Go
39 lines
881 B
Go
|
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
|
||
|
}
|