Working on content type negotiation API
This commit is contained in:
26
utils.go
26
utils.go
@ -8,6 +8,7 @@ import (
|
||||
"encoding/xml"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type H map[string]interface{}
|
||||
@ -45,6 +46,31 @@ func filterFlags(content string) string {
|
||||
return content
|
||||
}
|
||||
|
||||
func readData(key string, config map[string]interface{}) interface{} {
|
||||
data, ok := config[key]
|
||||
if ok {
|
||||
return data
|
||||
}
|
||||
data, ok = config["*.data"]
|
||||
if !ok {
|
||||
panic("negotiation config is invalid")
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
func parseAccept(accept string) []string {
|
||||
parts := strings.Split(accept, ",")
|
||||
for i, part := range parts {
|
||||
index := strings.IndexByte(part, ';')
|
||||
if index >= 0 {
|
||||
part = part[0:index]
|
||||
}
|
||||
part = strings.TrimSpace(part)
|
||||
parts[i] = part
|
||||
}
|
||||
return parts
|
||||
}
|
||||
|
||||
func funcName(f interface{}) string {
|
||||
return runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
|
||||
}
|
||||
|
Reference in New Issue
Block a user