-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
mimefix.go
48 lines (42 loc) · 1.21 KB
/
mimefix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Package mimefix provides functionalities to bypass
// this issue with fasthttp on windows hosts*:
// https://github.com/golang/go/issues/32350
package mimefix
import (
"mime"
"strings"
)
const (
expectedJSMimeType = "application/javascript"
)
// Check gets the detected mime type for .js
// files and returns it. Also it is checked
// against the expected mime type so that true
// is returned if the value matches the expected
// mime type.
func Check() (curr string, ok bool) {
curr = mime.TypeByExtension(".js")
ok = strings.HasPrefix(curr, expectedJSMimeType)
return
}
// Fix loads the os-dependent fixer and executes
// the Fix function. An error is returned when the
// fix routine failed.
func Fix() error {
return new(mimeFixer).Fix(expectedJSMimeType)
}
// CheckFix first executes Check(). If the current
// value is alredy set ot the expected value, no
// further action is performed. Otherwise, fix is
// executed.
//
// Returns the current mime string value, true if
// Check() returned true and an error when Fix()
// was executed and has failed.
func CheckFix() (curr string, ok bool, err error) {
if curr, ok = Check(); ok {
return
}
err = Fix()
return
}