forked from pierrre/imageserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
processor.go
63 lines (52 loc) · 1.45 KB
/
processor.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
package image
import (
"image"
"github.com/Destinia/imageserver"
)
// Processor processes a Go Image.
//
// It can return the given Image, but should not modify it.
type Processor interface {
Process(image.Image, imageserver.Params) (image.Image, error)
Changer
}
// ProcessorFunc is a Processor func.
type ProcessorFunc func(image.Image, imageserver.Params) (image.Image, error)
// Process implements Processor.
func (f ProcessorFunc) Process(nim image.Image, params imageserver.Params) (image.Image, error) {
return f(nim, params)
}
// Change implements Processor.
func (f ProcessorFunc) Change(params imageserver.Params) bool {
return true
}
// ListProcessor is a Processor implementation that wrap a list of Processor.
type ListProcessor []Processor
// Process implements Processor.
func (prc ListProcessor) Process(nim image.Image, params imageserver.Params) (image.Image, error) {
for _, p := range prc {
var err error
nim, err = p.Process(nim, params)
if err != nil {
return nil, err
}
}
return nim, nil
}
// Change implements Processor.
func (prc ListProcessor) Change(params imageserver.Params) bool {
for _, p := range prc {
if p.Change(params) {
return true
}
}
return false
}
// ChangeProcessor is a Processor implementation that alway return true for the Change method.
type ChangeProcessor struct {
Processor
}
// Change implements Processor.
func (prc *ChangeProcessor) Change(params imageserver.Params) bool {
return true
}