-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmain.go
63 lines (48 loc) · 1.36 KB
/
main.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 media_library
import (
"database/sql/driver"
"image"
"io"
"strings"
"github.com/jinzhu/gorm"
"github.com/qor/qor/utils"
"os"
)
// 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
}
// URLTemplater is a interface to return url template
type URLTemplater interface {
GetURLTemplate(*Option) string
}
// MediaLibrary 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) (*os.File, error)
IsImage() bool
URL(style ...string) string
Ext() string
String() string
}
// Option media library option
type Option map[string]string
// Get used to get option with name
func (option Option) Get(key string) string {
return option[strings.ToUpper(key)]
}
func parseTagOption(str string) *Option {
option := Option(utils.ParseTagOption(str))
return &option
}