2018-01-29 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libgo / go / mime / type_unix.go
blob8e177ca14ee9d776a39998e4650565c79983a6d3
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 aix darwin dragonfly freebsd linux nacl netbsd openbsd solaris
7 package mime
9 import (
10 "bufio"
11 "os"
12 "strings"
15 func init() {
16 osInitMime = initMimeUnix
19 var typeFiles = []string{
20 "/etc/mime.types",
21 "/etc/apache2/mime.types",
22 "/etc/apache/mime.types",
25 func loadMimeFile(filename string) {
26 f, err := os.Open(filename)
27 if err != nil {
28 return
30 defer f.Close()
32 scanner := bufio.NewScanner(f)
33 for scanner.Scan() {
34 fields := strings.Fields(scanner.Text())
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)
46 if err := scanner.Err(); err != nil {
47 panic(err)
51 func initMimeUnix() {
52 for _, filename := range typeFiles {
53 loadMimeFile(filename)
57 func initMimeForTests() map[string]string {
58 typeFiles = []string{"testdata/test.types"}
59 return map[string]string{
60 ".T1": "application/test",
61 ".t2": "text/test; charset=utf-8",
62 ".png": "image/png",