Validate checks if the configuration is valid
()
| 108 | |
| 109 | // Validate checks if the configuration is valid |
| 110 | func (c *Config) Validate() error { |
| 111 | if c.WatermarkOpacity <= 0 || c.WatermarkOpacity > 1 { |
| 112 | return IMGPROXY_WATERMARK_OPACITY.Errorf("must be between 0 and 1") |
| 113 | } |
| 114 | |
| 115 | if c.Quality < 1 || c.Quality > 100 { |
| 116 | return IMGPROXY_QUALITY.Errorf("must be between 1 and 100") |
| 117 | } |
| 118 | |
| 119 | for imgtype, minQ := range c.FormatQuality { |
| 120 | if minQ < 1 || minQ > 100 { |
| 121 | return IMGPROXY_FORMAT_QUALITY.Errorf("format %s: must be between 1 and 100", imgtype.String()) |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | filtered := c.PreferredFormats[:0] |
| 126 | |
| 127 | for _, t := range c.PreferredFormats { |
| 128 | if !vips.SupportsSave(t) { |
| 129 | IMGPROXY_PREFERRED_FORMATS.Warn("can't be a preferred format as it's saving is not supported", "format", t) |
| 130 | } else { |
| 131 | filtered = append(filtered, t) |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | if len(filtered) == 0 { |
| 136 | return IMGPROXY_PREFERRED_FORMATS.Errorf("no supported preferred formats specified") |
| 137 | } |
| 138 | |
| 139 | c.PreferredFormats = filtered |
| 140 | |
| 141 | return nil |
| 142 | } |
no test coverage detected