-
Notifications
You must be signed in to change notification settings - Fork 29
/
uri_helper.go
56 lines (47 loc) · 1.17 KB
/
uri_helper.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
49
50
51
52
53
54
55
56
package toolbox
import (
"net/url"
"path"
)
//FileSchema file://
var FileSchema = "file://"
//Deprecated start using url.Resource
//ExtractMimeType extracts mime type by extension
func ExtractMimeType(file string) string {
extension := path.Ext(file)
if len(extension) > 1 {
extension = extension[1:]
}
if mimeType, ok := FileExtensionMimeType[extension]; ok {
return mimeType
}
return "text/plain"
}
//QueryIntValue returns query value for passed in url's name or default value
func QueryIntValue(u *url.URL, name string, defaultValue int) int {
value := u.Query().Get(name)
if value == "" {
return defaultValue
}
result := AsInt(value)
if result != 0 {
return result
}
return defaultValue
}
//QueryBoolValue returns query value for passed in url's name or default value
func QueryBoolValue(u *url.URL, name string, defaultValue bool) bool {
value := u.Query().Get(name)
if value == "" {
return defaultValue
}
return AsBoolean(value)
}
//QueryValue returns query value for passed in url's name or default value
func QueryValue(u *url.URL, name, defaultValue string) string {
value := u.Query().Get(name)
if value == "" {
return defaultValue
}
return value
}