-
Notifications
You must be signed in to change notification settings - Fork 14
/
util.go
49 lines (40 loc) · 978 Bytes
/
util.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
package main
import (
"log"
"net/http"
"os"
"reflect"
)
func in_array(val interface{}, array interface{}) bool {
return at_array(val, array) != -1
}
func at_array(val interface{}, array interface{}) (index int) {
index = -1
switch reflect.TypeOf(array).Kind() {
case reflect.Slice:
s := reflect.ValueOf(array)
for i := 0; i < s.Len(); i++ {
if reflect.DeepEqual(val, s.Index(i).Interface()) == true {
index = i
return
}
}
}
return
}
func getMimeType(file *os.File) (string, error) {
// Only the first 512 bytes are used to sniff the content type.
buffer := make([]byte, 512)
_, readError := file.Read(buffer)
if readError != nil {
debugInfo("Read error for file: " + file.Name())
return "error", readError
}
// Always returns a valid content-type and "application/octet-stream" if no others seemed to match.
return http.DetectContentType(buffer), nil
}
func debugInfo(message string) {
if verbose {
log.Println(message)
}
}