mirror of https://github.com/golang/go.git
mime: use Scanner to read mime files during init
Also close the file when we're done. R=bradfitz CC=golang-dev https://golang.org/cl/7363045
This commit is contained in:
parent
cbd2c7a283
commit
35367cc641
|
|
@ -23,15 +23,11 @@ func loadMimeFile(filename string) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
reader := bufio.NewReader(f)
|
scanner := bufio.NewScanner(f)
|
||||||
for {
|
for scanner.Scan() {
|
||||||
line, err := reader.ReadString('\n')
|
fields := strings.Fields(scanner.Text())
|
||||||
if err != nil {
|
|
||||||
f.Close()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fields := strings.Fields(line)
|
|
||||||
if len(fields) <= 1 || fields[0][0] == '#' {
|
if len(fields) <= 1 || fields[0][0] == '#' {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -43,6 +39,9 @@ func loadMimeFile(filename string) {
|
||||||
setExtensionType("."+ext, mimeType)
|
setExtensionType("."+ext, mimeType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initMime() {
|
func initMime() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue