forked from pierrre/imageserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
39 lines (32 loc) · 839 Bytes
/
provider.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
package image
import (
"image"
"github.com/Destinia/imageserver"
)
// Provider returns a Go Image.
type Provider interface {
Get(imageserver.Params) (image.Image, error)
}
// ProviderFunc is a Provider func.
type ProviderFunc func(imageserver.Params) (image.Image, error)
// Get implements Provider.
func (f ProviderFunc) Get(params imageserver.Params) (image.Image, error) {
return f(params)
}
// ProcessorProvider is a Provider implementation that processes the Image.
type ProcessorProvider struct {
Provider
Processor Processor
}
// Get implements Provider.
func (prv *ProcessorProvider) Get(params imageserver.Params) (image.Image, error) {
nim, err := prv.Provider.Get(params)
if err != nil {
return nil, err
}
nim, err = prv.Processor.Process(nim, params)
if err != nil {
return nil, err
}
return nim, nil
}