-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
56 lines (46 loc) · 1.18 KB
/
options.go
File metadata and controls
56 lines (46 loc) · 1.18 KB
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 imageboss
import (
"fmt"
"strings"
)
// Option is a path-segment option (e.g. blur:4, format:auto).
type Option interface {
PathSegment() string
}
// Param is an Option built from key and value(s). Implements Option.
func Param(key string, values ...string) Option {
return paramOption{key: key, values: values}
}
type paramOption struct {
key string
values []string
}
func (p paramOption) PathSegment() string {
if p.key == "" {
return ""
}
if len(p.values) == 0 {
return p.key
}
return p.key + ":" + strings.Join(p.values, ",")
}
// Opt creates a single key:value path segment for ImageBoss options.
func Opt(key, value string) Option {
return Param(key, value)
}
// FormatAuto adds format:auto option.
func FormatAuto() Option {
return Opt("format", "auto")
}
// Blur adds blur:N option (0–40, 2–4 recommended).
func Blur(n int) Option {
return Opt("blur", fmt.Sprintf("%d", n))
}
// Download adds download option (force download). Use DownloadFilename for custom name.
func Download() Option {
return Opt("download", "1")
}
// DownloadFilename adds download:filename option.
func DownloadFilename(filename string) Option {
return Opt("download", filename)
}