1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package flexCdn
- import (
- "context"
- "github.com/go-nunu/nunu-layout-advanced/internal/repository"
- )
- type CcIpListRepository interface {
- GetCcIpList(ctx context.Context, serverId int64) ([]string, error)
- GetHttpWebId(ctx context.Context, serverId int64) (int64, error)
- GetIpListId(ctx context.Context, serverId int64,ipListType string) (int64,error)
- GetIpId(ctx context.Context, ipListId int64,ip string,sourceCategory string) (int64,error)
- GetCcIpCount(ctx context.Context,ipListId int64, ip string,sourceCategory string) (int64, error)
- }
- func NewCcIpListRepository(
- repository *repository.Repository,
- ) CcIpListRepository {
- return &ccIpListRepository{
- Repository: repository,
- }
- }
- type ccIpListRepository struct {
- *repository.Repository
- }
- func (r *ccIpListRepository) GetCcIpList(ctx context.Context, serverId int64) ([]string, error) {
- ipListId, err := r.GetIpListId(ctx, serverId,"white")
- if err != nil {
- return nil, err
- }
- var ips []string
- return ips, r.DBWithName(ctx,"cdn").Table("cloud_ip_items").Where("listId = ? AND sourceCategory = ?", ipListId, "cc").Select("value").Scan(&ips).Error
- }
- func (r *ccIpListRepository) GetHttpWebId(ctx context.Context, serverId int64) (int64, error) {
- var webId int64
- return webId, r.DBWithName(ctx,"cdn").Table("cloud_servers").Where("id = ?", serverId).Select("webId").Scan(&webId).Error
- }
- func (r *ccIpListRepository) GetIpListId(ctx context.Context, serverId int64,ipListType string) (int64,error) {
- var ipListId int64
- return ipListId, r.DBWithName(ctx,"cdn").Table("cloud_ip_lists").Where("serverId = ? AND type = ?", serverId,ipListType).Select("id").Scan(&ipListId).Error
- }
- func (r *ccIpListRepository) GetIpId(ctx context.Context, ipListId int64,ip string,sourceCategory string) (int64,error) {
- var ipId int64
- return ipId, r.DBWithName(ctx,"cdn").Table("cloud_ip_items").Where("listId = ? AND value = ? AND sourceCategory = ?", ipListId,ip,sourceCategory).Order("id desc").Limit(1).Select("id").Scan(&ipId).Error
- }
- func (r *ccIpListRepository) GetCcIpCount(ctx context.Context,ipListId int64, ip string,sourceCategory string) (int64, error) {
- var count int64
- return count, r.DBWithName(ctx,"cdn").Table("cloud_ip_items").Where("listId = ? AND value = ? AND sourceCategory = ?", ipListId,ip,sourceCategory).Count(&count).Error
- }
|