mirror of
https://github.com/gin-gonic/gin.git
synced 2025-05-20 00:47:00 +08:00
Splitting source code in different files
This commit is contained in:
51
utils.go
Normal file
51
utils.go
Normal file
@ -0,0 +1,51 @@
|
||||
package gin
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"path"
|
||||
)
|
||||
|
||||
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 joinGroupPath(elems ...string) string {
|
||||
joined := path.Join(elems...)
|
||||
lastComponent := elems[len(elems)-1]
|
||||
// Append a '/' if the last component had one, but only if it's not there already
|
||||
if len(lastComponent) > 0 && lastComponent[len(lastComponent)-1] == '/' && joined[len(joined)-1] != '/' {
|
||||
return joined + "/"
|
||||
}
|
||||
return joined
|
||||
}
|
||||
|
||||
func filterFlags(content string) string {
|
||||
for i, a := range content {
|
||||
if a == ' ' || a == ';' {
|
||||
return content[:i]
|
||||
}
|
||||
}
|
||||
return content
|
||||
}
|
Reference in New Issue
Block a user