|
| 1 | +package cache |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/google/uuid" |
| 5 | + |
| 6 | + "dillmann.com.br/nginx-ignition/core/cache" |
| 7 | +) |
| 8 | + |
| 9 | +func toDomain(id uuid.UUID, dto *cacheRequestDto) *cache.Cache { |
| 10 | + durations := make([]cache.Duration, len(dto.Durations)) |
| 11 | + for index, duration := range dto.Durations { |
| 12 | + durations[index] = cache.Duration{ |
| 13 | + StatusCodes: duration.StatusCodes, |
| 14 | + ValidTimeSeconds: duration.ValidTimeSeconds, |
| 15 | + } |
| 16 | + } |
| 17 | + |
| 18 | + return &cache.Cache{ |
| 19 | + ID: id, |
| 20 | + Name: dto.Name, |
| 21 | + StoragePath: dto.StoragePath, |
| 22 | + InactiveSeconds: dto.InactiveSeconds, |
| 23 | + MaximumSizeMB: dto.MaximumSizeMB, |
| 24 | + AllowedMethods: dto.AllowedMethods, |
| 25 | + MinimumUsesBeforeCaching: dto.MinimumUsesBeforeCaching, |
| 26 | + UseStale: dto.UseStale, |
| 27 | + BackgroundUpdate: dto.BackgroundUpdate, |
| 28 | + Revalidate: dto.Revalidate, |
| 29 | + BypassRules: dto.BypassRules, |
| 30 | + NoCacheRules: dto.NoCacheRules, |
| 31 | + FileExtensions: dto.FileExtensions, |
| 32 | + IgnoreUpstreamCacheHeaders: dto.IgnoreUpstreamCacheHeaders, |
| 33 | + CacheStatusResponseHeaderEnabled: dto.CacheStatusResponseHeaderEnabled, |
| 34 | + Durations: durations, |
| 35 | + ConcurrencyLock: cache.ConcurrencyLock{ |
| 36 | + Enabled: dto.ConcurrencyLock.Enabled, |
| 37 | + TimeoutSeconds: dto.ConcurrencyLock.TimeoutSeconds, |
| 38 | + AgeSeconds: dto.ConcurrencyLock.AgeSeconds, |
| 39 | + }, |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +func toResponseDto(domain *cache.Cache) cacheResponseDto { |
| 44 | + durations := make([]durationDto, len(domain.Durations)) |
| 45 | + for index, duration := range domain.Durations { |
| 46 | + durations[index] = durationDto{ |
| 47 | + StatusCodes: duration.StatusCodes, |
| 48 | + ValidTimeSeconds: duration.ValidTimeSeconds, |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + return cacheResponseDto{ |
| 53 | + ID: domain.ID, |
| 54 | + Name: domain.Name, |
| 55 | + StoragePath: domain.StoragePath, |
| 56 | + InactiveSeconds: domain.InactiveSeconds, |
| 57 | + MaximumSizeMB: domain.MaximumSizeMB, |
| 58 | + AllowedMethods: domain.AllowedMethods, |
| 59 | + MinimumUsesBeforeCaching: domain.MinimumUsesBeforeCaching, |
| 60 | + UseStale: domain.UseStale, |
| 61 | + BackgroundUpdate: domain.BackgroundUpdate, |
| 62 | + Revalidate: domain.Revalidate, |
| 63 | + BypassRules: domain.BypassRules, |
| 64 | + NoCacheRules: domain.NoCacheRules, |
| 65 | + FileExtensions: domain.FileExtensions, |
| 66 | + IgnoreUpstreamCacheHeaders: domain.IgnoreUpstreamCacheHeaders, |
| 67 | + CacheStatusResponseHeaderEnabled: domain.CacheStatusResponseHeaderEnabled, |
| 68 | + Durations: durations, |
| 69 | + ConcurrencyLock: concurrencyLockDto{ |
| 70 | + Enabled: domain.ConcurrencyLock.Enabled, |
| 71 | + TimeoutSeconds: domain.ConcurrencyLock.TimeoutSeconds, |
| 72 | + AgeSeconds: domain.ConcurrencyLock.AgeSeconds, |
| 73 | + }, |
| 74 | + } |
| 75 | +} |
0 commit comments