libgo: Update to Go 1.3 release.
[official-gcc.git] / libgo / go / mime / type_unix.go
blob1d394315a49b0cafd80d0177340a6f6c1d983e55
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",