Fix bootstrap/PR63632
[official-gcc.git] / libgo / go / mime / type_plan9.go
blobb8f0511ee7d6530b1aca49cda88819f7502e67ce
1 // Copyright 2013 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 package mime
7 import (
8 "bufio"
9 "os"
10 "strings"
13 var typeFiles = []string{
14 "/sys/lib/mimetypes",
17 func loadMimeFile(filename string) {
18 f, err := os.Open(filename)
19 if err != nil {
20 return
22 defer f.Close()
24 scanner := bufio.NewScanner(f)
25 for scanner.Scan() {
26 fields := strings.Fields(scanner.Text())
27 if len(fields) <= 2 || fields[0][0] != '.' {
28 continue
30 if fields[1] == "-" || fields[2] == "-" {
31 continue
33 setExtensionType(fields[0], fields[1]+"/"+fields[2])
35 if err := scanner.Err(); err != nil {
36 panic(err)
40 func initMime() {
41 for _, filename := range typeFiles {
42 loadMimeFile(filename)
46 func initMimeForTests() map[string]string {
47 typeFiles = []string{"testdata/test.types.plan9"}
48 return map[string]string{
49 ".t1": "application/test",
50 ".t2": "text/test; charset=utf-8",
51 ".png": "image/png",