/
main.go
64 lines (50 loc) · 1.13 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
64
package media_library
import (
"database/sql/driver"
"image"
"io"
"strings"
"github.com/jinzhu/gorm"
"os"
)
type Size struct {
Width int
Height int
}
type URLTemplater interface {
GetURLTemplate(*Option) string
}
type MediaLibrary 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
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
String() string
}
type Option map[string]string
func (option Option) Get(key string) string {
return option[key]
}
func parseTagOption(str string) *Option {
tags := strings.Split(str, ";")
setting := Option{}
for _, value := range tags {
v := strings.Split(value, ":")
k := strings.TrimSpace(strings.ToUpper(v[0]))
if len(v) == 2 {
setting[k] = v[1]
} else {
setting[k] = k
}
}
return &setting
}