@@ -21,10 +21,10 @@ import (
2121)
2222
2323type fileInfo struct {
24- name string
25- mime_type string
26- mtime time.Time
27- size int64
24+ name string
25+ mimeType string
26+ mtime time.Time
27+ size int64
2828}
2929
3030type fileSorter struct {
@@ -46,53 +46,54 @@ func (fi *fileSorter) Less(i, j int) bool {
4646 return strings .ToLower (fi .files [i ].name ) < strings .ToLower (fi .files [j ].name )
4747}
4848
49- func (this * fileInfo ) to_json () string {
50- name , _ := json .Marshal (this .name )
51- return fmt .Sprintf (`{"name": %s, "mime_type": "%s", "mtime": "%s", "size": %d}` , string (name ), this .mime_type , this .mtime .Format (http .TimeFormat ), this .size )
49+ func (f * fileInfo ) toJson () string {
50+ name , _ := json .Marshal (f .name )
51+ return fmt .Sprintf (`{"name": %s, "mime_type": "%s", "mtime": "%s", "size": %d}` ,
52+ string (name ), f .mimeType , f .mtime .Format (http .TimeFormat ), f .size )
5253}
5354
54- func directory_fileInfos (fis []os.FileInfo , full_path string ) []fileInfo {
55- file_infos := []fileInfo {}
55+ func directoryFileInfos (fis []os.FileInfo , fullPath string ) []fileInfo {
56+ fileInfos := make ( []fileInfo , 0 )
5657 for i := range fis {
5758 if fis [i ].Name ()[0 ] == '.' {
5859 continue
5960 }
60- fileInfo := fileInfo {
61+ fileInfo := fileInfo {
6162 name : fis [i ].Name (),
6263 mtime : fis [i ].ModTime (),
6364 }
64- if fis [i ].IsDir () || isSymlinkDir (fis [i ], full_path ) {
65- fileInfo .mime_type = "text/directory"
65+ if fis [i ].IsDir () || isSymlinkDir (fis [i ], fullPath ) {
66+ fileInfo .mimeType = "text/directory"
6667 fileInfo .size = 0
6768 } else {
68- fileInfo .mime_type = getContentType (fis [i ].Name ())
69+ fileInfo .mimeType = getContentType (fis [i ].Name ())
6970 fileInfo .size = fis [i ].Size ()
7071 }
71- file_infos = append (file_infos , fileInfo )
72+ fileInfos = append (fileInfos , fileInfo )
7273 }
7374
74- sorter := & fileSorter {files : file_infos }
75+ sorter := & fileSorter {files : fileInfos }
7576
7677 sort .Sort (sorter )
7778
78- return file_infos
79+ return fileInfos
7980}
8081
81- func dirToJSON (osFile * os.File , full_path string ) (string , error ) {
82+ func dirToJSON (osFile * os.File , fullPath string ) (string , error ) {
8283 fis , err := osFile .Readdir (0 )
8384 if err != nil {
8485 return "" , err
8586 }
8687
87- file_infos := directory_fileInfos (fis , full_path )
88+ fileInfos := directoryFileInfos (fis , fullPath )
8889
89- if len (file_infos ) == 0 {
90+ if len (fileInfos ) == 0 {
9091 return "[]" , nil
9192 }
9293
93- ss := []string {}
94- for i := range file_infos {
95- temp := file_infos [i ].to_json ()
94+ ss := make ( []string , 0 )
95+ for i := range fileInfos {
96+ temp := fileInfos [i ].toJson ()
9697 ss = append (ss , temp )
9798 }
9899
@@ -140,7 +141,7 @@ func getContentType(fileName string) string {
140141 ".wtv" : "video/x-ms-wtv" ,
141142 ".flv" : "video/x-flv" ,
142143 ".3gp" : "video/3gpp" ,
143- ".webm" : "video/webm" ,
144+ ".webm" : "video/webm" ,
144145 ".epub" : "application/epub+zip" ,
145146 ".mobi" : "application/x-mobipocket" ,
146147 ".zip" : "application/zip" ,
@@ -173,12 +174,12 @@ func getContentType(fileName string) string {
173174 ".html" : "text/html" ,
174175 ".htm" : "text/html" ,
175176 // subtitle stuff, with others below
176- ".srt" : "application/x-subrip" ,
177- ".sub" : "text/vnd.dvb.subtitle" ,
177+ ".srt" : "application/x-subrip" ,
178+ ".sub" : "text/vnd.dvb.subtitle" ,
178179 }
179180
180- sub_extensions := []string {".idx" , ".sub" , ".srt" , ".ssa" , ".ass" , ".smi" , ".utf" , ".utf8" , ".utf-8" , ".rt" , ".aqt" , ".usf" , ".jss" , ".cdg" , ".psb" , ".mpsub" , ".mpl2" , ".pjs" , ".dks" , ".stl" , ".vtt" }
181- for _ , e := range sub_extensions {
181+ subExtensions := []string {".idx" , ".sub" , ".srt" , ".ssa" , ".ass" , ".smi" , ".utf" , ".utf8" , ".utf-8" , ".rt" , ".aqt" , ".usf" , ".jss" , ".cdg" , ".psb" , ".mpsub" , ".mpl2" , ".pjs" , ".dks" , ".stl" , ".vtt" }
182+ for _ , e := range subExtensions {
182183 encodingMap [e ] = "application/x-subtitle"
183184 }
184185
0 commit comments