forked from SoCloz/goprismic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
media_link.go
48 lines (42 loc) · 912 Bytes
/
media_link.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
package link
import (
"fmt"
"reflect"
)
// A link to a file
type MediaLink struct {
File struct {
Url string
Kind string
Filename string
}
}
func (l *MediaLink) Decode(enc interface{}) error {
dec, ok := enc.(map[string]interface{})
if !ok {
return fmt.Errorf("unable to decode link content : %+v is a %s, not a map", enc, reflect.TypeOf(enc))
}
if v, found := dec["file"]; found {
doc, ok := v.(map[string]interface{})
if !ok {
return fmt.Errorf("%+v is not a map", v)
}
if v, found := doc["url"]; found {
l.File.Url = v.(string)
}
if v, found := doc["kind"]; found {
l.File.Kind = v.(string)
}
if v, found := doc["filename"]; found {
l.File.Filename = v.(string)
}
}
return nil
}
func (l *MediaLink) GetUrl() string {
return l.File.Url
}
func (l *MediaLink) GetText() string {
return l.File.Filename
}
func (l *MediaLink) Resolve(_ Resolver) {}