-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
66 lines (55 loc) · 1.29 KB
/
config.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
package main
import (
"errors"
)
//contentTypes - a list of types to use in the retreival of data from WP
func contentTypes() []string {
return []string{"posts", "media", "users", "categories", "tags"}
}
// imageFileExtFromMimeType - returns the file extension based on the mime type
// t - mime type
func imageFileExtFromMimeType(t string) (string, error) {
m := make(map[string]string)
m["image/png"] = "png"
m["image/jpeg"] = "jpg"
m["image/gif"] = "gif"
m["image/tiff"] = "tiff"
m["image/bmp"] = "bmp"
m["image/webp"] = "webp"
m["image/svg+xml"] = "svg"
if v, ok := m[t]; ok {
return v, nil
}
err := errors.New("Mime type does not exist")
return "", err
}
// directoryFromStruct - gets the directory to use based on the type of the struct passed in
// s - struct to use (e.g. post)
// isExport - wether this is for the exprt data
func directoryFromStruct(s interface{}, isExport bool) string {
d := ""
switch s.(type) {
case post:
d = "data/api/posts"
if isExport {
d = "data/export/posts"
}
case media:
d = "data/api/media"
if isExport {
d = "data/export/files"
}
case author:
d = "data/api/users"
if isExport {
d = "data/export/authors"
}
case category:
d = "data/api/categories"
case tag:
d = "data/api/tags"
default:
d = "data/api"
}
return d
}