2014-08-29 21:49:50 +04:00
|
|
|
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2014-07-16 22:14:03 +04:00
|
|
|
package gin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
2014-08-19 05:40:52 +04:00
|
|
|
"reflect"
|
|
|
|
"runtime"
|
2014-08-31 00:22:57 +04:00
|
|
|
"strings"
|
2014-07-16 22:14:03 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
type H map[string]interface{}
|
|
|
|
|
|
|
|
// Allows type H to be used with xml.Marshal
|
|
|
|
func (h H) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
|
|
|
start.Name = xml.Name{
|
|
|
|
Space: "",
|
|
|
|
Local: "map",
|
|
|
|
}
|
|
|
|
if err := e.EncodeToken(start); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for key, value := range h {
|
|
|
|
elem := xml.StartElement{
|
|
|
|
Name: xml.Name{Space: "", Local: key},
|
|
|
|
Attr: []xml.Attr{},
|
|
|
|
}
|
|
|
|
if err := e.EncodeElement(value, elem); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := e.EncodeToken(xml.EndElement{Name: start.Name}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func filterFlags(content string) string {
|
|
|
|
for i, a := range content {
|
|
|
|
if a == ' ' || a == ';' {
|
|
|
|
return content[:i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return content
|
|
|
|
}
|
2014-08-19 05:40:52 +04:00
|
|
|
|
2014-08-31 00:22:57 +04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2014-08-19 05:40:52 +04:00
|
|
|
func funcName(f interface{}) string {
|
|
|
|
return runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
|
|
|
|
}
|