-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
79 lines (67 loc) · 1.75 KB
/
options.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package identicon
import (
"hash"
"hash/fnv"
"image/color"
)
// Options define customizable settings
type Options struct {
Resolution int
ImageSize int
Hasher hash.Hash
BGColor color.Color
FGColor color.Color
}
// Option changes a single option
type Option func(*Identicon)
// DefaultOptions are the baseline for a new identicon
func DefaultOptions() *Options {
return &Options{
BGColor: color.NRGBA{240, 240, 240, 255},
Resolution: 5,
ImageSize: 100,
Hasher: fnv.New128(),
}
}
// WithBGColor returns an option that sets the identicon's background color to given color.
func WithBGColor(c color.Color) Option {
return func(i *Identicon) {
i.options.BGColor = c
}
}
// WithFGColor returns an option that sets the identicon's background color to given color.
func WithFGColor(c color.Color) Option {
return func(i *Identicon) {
i.options.FGColor = c
}
}
// WithResolution returns an option that sets the identicon's grid resolution to given amount.
// The option will be discarded silently if given value is non-positive.
func WithResolution(resolution int) Option {
return func(i *Identicon) {
if resolution <= 0 {
return
}
i.options.Resolution = resolution
}
}
// WithImageSize returns an option that sets the identicon's image size to given amount.
// The option will be discarded silently if given value is non-positive.
func WithImageSize(size int) Option {
return func(i *Identicon) {
if size <= 0 {
return
}
i.options.ImageSize = size
}
}
// WithHasher returns an option that sets the identicon's hash generator.
// The option will be discarded silently if nil given.
func WithHasher(hasher hash.Hash) Option {
return func(i *Identicon) {
if hasher == nil {
return
}
i.options.Hasher = hasher
}
}