36 lines
792 B
Go
36 lines
792 B
Go
|
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
|
||
|
}
|