2015-09-24 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / libgo / go / mime / type_unix.go
blob3e404cf742997c7c85c08cdf19033171ed90ce3f
1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
7 package mime
9 import (
10 "bufio"
11 "os"
12 "strings"
15 var typeFiles = []string{
16 "/etc/mime.types",
17 "/etc/apache2/mime.types",
18 "/etc/apache/mime.types",
21 func loadMimeFile(filename string) {
22 f, err := os.Open(filename)
23 if err != nil {
24 return
26 defer f.Close()
28 scanner := bufio.NewScanner(f)
29 for scanner.Scan() {
30 fields := strings.Fields(scanner.Text())
31 if len(fields) <= 1 || fields[0][0] == '#' {
32 continue
34 mimeType := fields[0]
35 for _, ext := range fields[1:] {
36 if ext[0] == '#' {
37 break
39 setExtensionType("."+ext, mimeType)
42 if err := scanner.Err(); err != nil {
43 panic(err)
47 func initMime() {
48 for _, filename := range typeFiles {
49 loadMimeFile(filename)
53 func initMimeForTests() map[string]string {
54 typeFiles = []string{"testdata/test.types"}
55 return map[string]string{
56 ".T1": "application/test",
57 ".t2": "text/test; charset=utf-8",
58 ".png": "image/png",