12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- 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)
- }
- 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 = cc", ipListId).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).Select("id").Scan(&ipId).Error
- }
|