2013-02-11 Sebastian Huber <sebastian.huber@embedded-brains.de>
[official-gcc.git] / libgo / go / mime / type_unix.go
blob88eb83a735d167b34b157c220cfe22bd00208403
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 freebsd linux netbsd openbsd plan9
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
27 reader := bufio.NewReader(f)
28 for {
29 line, err := reader.ReadString('\n')
30 if err != nil {
31 f.Close()
32 return
34 fields := strings.Fields(line)
35 if len(fields) <= 1 || fields[0][0] == '#' {
36 continue
38 mimeType := fields[0]
39 for _, ext := range fields[1:] {
40 if ext[0] == '#' {
41 break
43 setExtensionType("."+ext, mimeType)
48 func initMime() {
49 for _, filename := range typeFiles {
50 loadMimeFile(filename)
54 func initMimeForTests() map[string]string {
55 typeFiles = []string{"testdata/test.types"}
56 return map[string]string{
57 ".t1": "application/test",
58 ".t2": "text/test; charset=utf-8",
59 ".png": "image/png",