-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
util.go
48 lines (43 loc) · 1017 Bytes
/
util.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
//Author:TruthHun
//Email:TruthHun@QQ.COM
//Date:2018-01-21
package converter
import (
"encoding/json"
"io/ioutil"
"strings"
)
//media-type
var MediaType = map[string]string{
".jpeg": "image/jpeg",
".png": "image/png",
".jpg": "image/jpeg",
".gif": "image/gif",
".ico": "image/x-icon",
".bmp": "image/bmp",
".html": "application/xhtml+xml",
".xhtml": "application/xhtml+xml",
".htm": "application/xhtml+xml",
".otf": "application/x-font-opentype",
".ttf": "application/x-font-ttf",
".js": "application/x-javascript",
".ncx": "x-dtbncx+xml",
".txt": "text/plain",
".xml": "text/xml",
".css": "text/css",
}
//根据文件扩展名,获取media-type
func GetMediaType(ext string) string {
if mt, ok := MediaType[strings.ToLower(ext)]; ok {
return mt
}
return ""
}
//解析配置文件
func parseConfig(configFile string) (cfg Config, err error) {
var b []byte
if b, err = ioutil.ReadFile(configFile); err == nil {
err = json.Unmarshal(b, &cfg)
}
return
}