cciplist.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package flexCdn
  2. import (
  3. "context"
  4. "github.com/go-nunu/nunu-layout-advanced/internal/repository"
  5. )
  6. type CcIpListRepository interface {
  7. GetCcIpList(ctx context.Context, serverId int64) ([]string, error)
  8. GetHttpWebId(ctx context.Context, serverId int64) (int64, error)
  9. GetIpListId(ctx context.Context, serverId int64,ipListType string) (int64,error)
  10. GetIpId(ctx context.Context, ipListId int64,ip string,sourceCategory string) (int64,error)
  11. GetCcIpCount(ctx context.Context,ipListId int64, ip string,sourceCategory string) (int64, error)
  12. }
  13. func NewCcIpListRepository(
  14. repository *repository.Repository,
  15. ) CcIpListRepository {
  16. return &ccIpListRepository{
  17. Repository: repository,
  18. }
  19. }
  20. type ccIpListRepository struct {
  21. *repository.Repository
  22. }
  23. func (r *ccIpListRepository) GetCcIpList(ctx context.Context, serverId int64) ([]string, error) {
  24. ipListId, err := r.GetIpListId(ctx, serverId,"white")
  25. if err != nil {
  26. return nil, err
  27. }
  28. var ips []string
  29. return ips, r.DBWithName(ctx,"cdn").Table("cloud_ip_items").Where("listId = ? AND sourceCategory = ?", ipListId, "cc").Select("value").Scan(&ips).Error
  30. }
  31. func (r *ccIpListRepository) GetHttpWebId(ctx context.Context, serverId int64) (int64, error) {
  32. var webId int64
  33. return webId, r.DBWithName(ctx,"cdn").Table("cloud_servers").Where("id = ?", serverId).Select("webId").Scan(&webId).Error
  34. }
  35. func (r *ccIpListRepository) GetIpListId(ctx context.Context, serverId int64,ipListType string) (int64,error) {
  36. var ipListId int64
  37. return ipListId, r.DBWithName(ctx,"cdn").Table("cloud_ip_lists").Where("serverId = ? AND type = ?", serverId,ipListType).Select("id").Scan(&ipListId).Error
  38. }
  39. func (r *ccIpListRepository) GetIpId(ctx context.Context, ipListId int64,ip string,sourceCategory string) (int64,error) {
  40. var ipId int64
  41. 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
  42. }
  43. func (r *ccIpListRepository) GetCcIpCount(ctx context.Context,ipListId int64, ip string,sourceCategory string) (int64, error) {
  44. var count int64
  45. return count, r.DBWithName(ctx,"cdn").Table("cloud_ip_items").Where("listId = ? AND value = ? AND sourceCategory = ?", ipListId,ip,sourceCategory).Count(&count).Error
  46. }