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

Function parseFromMap

options/parser/parse.go:288–308  ·  view source on GitHub ↗

parseFromMap parses an option value from a map of allowed values

(
	ctx context.Context,
	p *Parser,
	o *options.Options,
	key string,
	m map[string]T,
	args ...string,
)

Source from the content-addressed store, hash-verified

286
287// parseFromMap parses an option value from a map of allowed values
288func parseFromMap[T comparable](
289 ctx context.Context,
290 p *Parser,
291 o *options.Options,
292 key string,
293 m map[string]T,
294 args ...string,
295) error {
296 if err := p.ensureMaxArgs(ctx, key, args, 1); err != nil {
297 return err
298 }
299
300 v, ok := m[args[0]]
301 if !ok {
302 return newInvalidArgumentError(ctx, key, args[0], slices.Collect(maps.Keys(m))...)
303 }
304
305 o.Set(key, v)
306
307 return nil
308}
309
310func (p *Parser) parseGravityType(
311 ctx context.Context,

Callers 1

Calls 3

newInvalidArgumentErrorFunction · 0.85
ensureMaxArgsMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected