diff --git a/web/main.go b/web/main.go index 3583925..5f0c862 100644 --- a/web/main.go +++ b/web/main.go @@ -42,6 +42,16 @@ type ( } ) +var mimeTypes = map[string]string { + ".go": "text/plain", + ".rs": "text/plain", + ".c": "text/plain", + ".h": "text/plain", + ".cpp": "text/plain", + ".hpp": "text/plain", + ".java": "text/plain", +} + //go:embed dir.html var dirTemplateSrc string var dirTemplate = template.Must(template.New("dir").Parse(dirTemplateSrc)) @@ -83,8 +93,12 @@ func Handler(app *AppState) http.HandlerFunc { mimeType := "application/octet-stream" extPos := strings.LastIndex(info.Name(), ".") + ext := string(info.Name()[strings.LastIndex(info.Name(), "."):]) + fmt.Println(ext) if extPos != -1 { - if m := mime.TypeByExtension(info.Name()[extPos:]); m != "" { + if m := mime.TypeByExtension(ext); m != "" { + mimeType = m + } else if m, ok := mimeTypes[ext]; ok { mimeType = m } }