mindoc/converter/util.go

49 lines
1017 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//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
}