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

Method parsePreset

options/parser/presets.go:23–61  ·  view source on GitHub ↗

parsePreset parses a preset string and returns the name and options

(presetStr string)

Source from the content-addressed store, hash-verified

21
22// parsePreset parses a preset string and returns the name and options
23func (p *Parser) parsePreset(presetStr string) error {
24 presetStr = strings.Trim(presetStr, " ")
25
26 if len(presetStr) == 0 || strings.HasPrefix(presetStr, "#") {
27 return nil
28 }
29
30 parts := strings.Split(presetStr, "=")
31
32 if len(parts) != 2 {
33 return fmt.Errorf("invalid preset string: %s", presetStr)
34 }
35
36 name := strings.Trim(parts[0], " ")
37 if len(name) == 0 {
38 return fmt.Errorf("empty preset name: %s", presetStr)
39 }
40
41 value := strings.Trim(parts[1], " ")
42 if len(value) == 0 {
43 return fmt.Errorf("empty preset value: %s", presetStr)
44 }
45
46 optsStr := strings.Split(value, "/")
47
48 opts, rest := p.parseURLOptions(optsStr)
49
50 if len(rest) > 0 {
51 return fmt.Errorf("invalid preset value: %s", presetStr)
52 }
53
54 if p.presets == nil {
55 p.presets = make(map[string][]urlOption)
56 }
57
58 p.presets[name] = opts
59
60 return nil
61}
62
63// validatePresets validates all presets by applying them to a new Options instance
64func (p *Parser) validatePresets(ctx context.Context) error {

Callers 1

parsePresetsMethod · 0.95

Calls 4

parseURLOptionsMethod · 0.95
TrimMethod · 0.80
SplitMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected