cciplist.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. }
  12. func NewCcIpListRepository(
  13. repository *repository.Repository,
  14. ) CcIpListRepository {
  15. return &ccIpListRepository{
  16. Repository: repository,
  17. }
  18. }
  19. type ccIpListRepository struct {
  20. *repository.Repository
  21. }
  22. func (r *ccIpListRepository) GetCcIpList(ctx context.Context, serverId int64) ([]string, error) {
  23. ipListId, err := r.GetIpListId(ctx, serverId,"white")
  24. if err != nil {
  25. return nil, err
  26. }
  27. var ips []string
  28. return ips, r.DBWithName(ctx,"cdn").Table("cloud_ip_items").Where("listId = ? AND sourceCategory = cc", ipListId).Select("value").Scan(&ips).Error
  29. }
  30. func (r *ccIpListRepository) GetHttpWebId(ctx context.Context, serverId int64) (int64, error) {
  31. var webId int64
  32. return webId, r.DBWithName(ctx,"cdn").Table("cloud_servers").Where("id = ?", serverId).Select("webId").Scan(&webId).Error
  33. }
  34. func (r *ccIpListRepository) GetIpListId(ctx context.Context, serverId int64,ipListType string) (int64,error) {
  35. var ipListId int64
  36. return ipListId, r.DBWithName(ctx,"cdn").Table("cloud_ip_lists").Where("serverId = ? AND type = ?", serverId,ipListType).Select("id").Scan(&ipListId).Error
  37. }
  38. func (r *ccIpListRepository) GetIpId(ctx context.Context, ipListId int64,ip string,sourceCategory string) (int64,error) {
  39. var ipId int64
  40. return ipId, r.DBWithName(ctx,"cdn").Table("cloud_ip_items").Where("listId = ? AND value = ? AND sourceCategory = ?", ipListId,ip,sourceCategory).Select("id").Scan(&ipId).Error
  41. }