MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / Validate

Method Validate

processing/config.go:110–142  ·  view source on GitHub ↗

Validate checks if the configuration is valid

()

Source from the content-addressed store, hash-verified

108
109// Validate checks if the configuration is valid
110func (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}

Callers 1

NewFunction · 0.45

Calls 4

SupportsSaveFunction · 0.92
ErrorfMethod · 0.80
WarnMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected