forked from imgproxy/imgproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
presets.go
56 lines (40 loc) · 1.03 KB
/
presets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"strings"
)
type presets map[string]urlOptions
func parsePreset(p presets, presetStr string) error {
presetStr = strings.Trim(presetStr, " ")
if len(presetStr) == 0 || strings.HasPrefix(presetStr, "#") {
return nil
}
parts := strings.Split(presetStr, "=")
if len(parts) != 2 {
return fmt.Errorf("Invalid preset string: %s", presetStr)
}
name := strings.Trim(parts[0], " ")
if len(name) == 0 {
return fmt.Errorf("Empty preset name: %s", presetStr)
}
value := strings.Trim(parts[1], " ")
if len(value) == 0 {
return fmt.Errorf("Empty preset value: %s", presetStr)
}
optsStr := strings.Split(value, "/")
opts, rest := parseURLOptions(optsStr)
if len(rest) > 0 {
return fmt.Errorf("Invalid preset value: %s", presetStr)
}
p[name] = opts
return nil
}
func checkPresets(p presets) error {
var po processingOptions
for name, opts := range p {
if err := applyProcessingOptions(&po, opts); err != nil {
return fmt.Errorf("Error in preset `%s`: %s", name, err)
}
}
return nil
}