util.go 1017 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //Author:TruthHun
  2. //Email:[email protected]
  3. //Date:2018-01-21
  4. package converter
  5. import (
  6. "encoding/json"
  7. "io/ioutil"
  8. "strings"
  9. )
  10. //media-type
  11. var MediaType = map[string]string{
  12. ".jpeg": "image/jpeg",
  13. ".png": "image/png",
  14. ".jpg": "image/jpeg",
  15. ".gif": "image/gif",
  16. ".ico": "image/x-icon",
  17. ".bmp": "image/bmp",
  18. ".html": "application/xhtml+xml",
  19. ".xhtml": "application/xhtml+xml",
  20. ".htm": "application/xhtml+xml",
  21. ".otf": "application/x-font-opentype",
  22. ".ttf": "application/x-font-ttf",
  23. ".js": "application/x-javascript",
  24. ".ncx": "x-dtbncx+xml",
  25. ".txt": "text/plain",
  26. ".xml": "text/xml",
  27. ".css": "text/css",
  28. }
  29. //根据文件扩展名,获取media-type
  30. func GetMediaType(ext string) string {
  31. if mt, ok := MediaType[strings.ToLower(ext)]; ok {
  32. return mt
  33. }
  34. return ""
  35. }
  36. //解析配置文件
  37. func parseConfig(configFile string) (cfg Config, err error) {
  38. var b []byte
  39. if b, err = ioutil.ReadFile(configFile); err == nil {
  40. err = json.Unmarshal(b, &cfg)
  41. }
  42. return
  43. }