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

Method GetInt

options/options.go:191–230  ·  view source on GitHub ↗

GetInt retrieves an int value from the options. If the key does not exist, GetInt returns the provided default value. If the key exists but the value is of a different integer type, GetInt converts it to int. If the key exists but the value is not an integer type, GetInt panics.

(key string, def int)

Source from the content-addressed store, hash-verified

189// GetInt converts it to int.
190// If the key exists but the value is not an integer type, GetInt panics.
191func (o *Options) GetInt(key string, def int) int {
192 v, ok := o.m[key]
193 if !ok {
194 return def
195 }
196
197 switch t := v.(type) {
198 case int:
199 return t
200 case int8:
201 return int(t)
202 case int16:
203 return int(t)
204 case int32:
205 return int(t)
206 case int64:
207 if t > int64(math.MaxInt) || t < int64(math.MinInt) {
208 panic(fmt.Errorf("value %d for key %q exceeds int range", t, key))
209 }
210 return int(t)
211 case uint:
212 if t > uint(math.MaxInt) {
213 panic(fmt.Errorf("value %d for key %q exceeds int range", t, key))
214 }
215 return int(t)
216 case uint8:
217 return int(t)
218 case uint16:
219 return int(t)
220 case uint32:
221 return int(t)
222 case uint64:
223 if t > uint64(math.MaxInt) {
224 panic(fmt.Errorf("value %d for key %q exceeds int range", t, key))
225 }
226 return int(t)
227 default:
228 panic(newTypeMismatchError(key, v, def))
229 }
230}
231
232// GetFloat retrieves a float64 value from the options.
233// If the key does not exist, GetFloat returns the provided default value.

Callers 13

TestGetIntMethod · 0.45
TestParsePathResizeMethod · 0.45
TestParsePathSizeMethod · 0.45
TestParsePathWidthMethod · 0.45
TestParsePathHeightMethod · 0.45
TestParsePathQualityMethod · 0.45
TestParsePathPresetMethod · 0.45

Calls 2

newTypeMismatchErrorFunction · 0.85
ErrorfMethod · 0.80

Tested by 13

TestGetIntMethod · 0.36
TestParsePathResizeMethod · 0.36
TestParsePathSizeMethod · 0.36
TestParsePathWidthMethod · 0.36
TestParsePathHeightMethod · 0.36
TestParsePathQualityMethod · 0.36
TestParsePathPresetMethod · 0.36