add some common code file extensions as text/plain
This commit is contained in:
parent
d40dec3566
commit
56d8733a40
1 changed files with 15 additions and 1 deletions
16
web/main.go
16
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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue