-
Notifications
You must be signed in to change notification settings - Fork 18
/
media.go
68 lines (53 loc) · 1.42 KB
/
media.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
package media
import (
"database/sql/driver"
"image"
"io"
"strings"
"github.com/jinzhu/gorm"
)
// Media is an interface including methods that needs for a media library storage
type Media interface {
Scan(value interface{}) error
Value() (driver.Value, error)
GetURLTemplate(*Option) string
GetURL(option *Option, scope *gorm.Scope, field *gorm.Field, templater URLTemplater) string
GetFileHeader() FileHeader
GetFileName() string
GetSizes() map[string]*Size
NeedCrop() bool
Cropped(values ...bool) bool
GetCropOption(name string) *image.Rectangle
Store(url string, option *Option, reader io.Reader) error
Retrieve(url string) (FileInterface, error)
IsImage() bool
URL(style ...string) string
Ext() string
String() string
}
// FileInterface media file interface
type FileInterface interface {
io.ReadSeeker
io.Closer
}
// Size is a struct, used for `GetSizes` method, it will return a slice of Size, media library will crop images automatically based on it
type Size struct {
Width int
Height int
Padding bool
}
// URLTemplater is a interface to return url template
type URLTemplater interface {
GetURLTemplate(*Option) string
}
// Option media library option
type Option map[string]string
// get option with name
func (option Option) Get(key string) string {
return option[strings.ToUpper(key)]
}
// set option
func (option Option) Set(key string, val string) {
option[strings.ToUpper(key)] = val
return
}