Source File
build.go
Belonging Package
github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil
package xmlutil
import (
)
func ( interface{}, *xml.Encoder) error {
return buildXML(, , false)
}
func ( interface{}, *xml.Encoder, bool) error {
:= xmlBuilder{encoder: , namespaces: map[string]string{}}
:= NewXMLElement(xml.Name{})
if := .buildValue(reflect.ValueOf(), , ""); != nil {
return
}
for , := range .Children {
for , := range {
return StructToXML(, , )
}
}
return nil
}
type xmlBuilder struct {
encoder *xml.Encoder
namespaces map[string]string
}
func ( *xmlBuilder) ( reflect.Value, *XMLNode, reflect.StructTag) error {
= elemOf()
if !.IsValid() { // no need to handle zero values
return nil
} else if .Get("location") != "" { // don't handle non-body location values
return nil
}
:= .Get("xml")
if len() != 0 {
:= strings.SplitAfterN(, ",", 2)[0]
if == "-" {
return nil
}
}
:= .Get("type")
if == "" {
switch .Kind() {
case reflect.Struct:
= "structure"
case reflect.Slice:
= "list"
case reflect.Map:
= "map"
}
}
switch {
case "structure":
if , := .Type().FieldByName("_"); {
= + reflect.StructTag(" ") + .Tag
}
return .buildStruct(, , )
case "list":
return .buildList(, , )
case "map":
return .buildMap(, , )
default:
return .buildScalar(, , )
}
}
if := .Get("payload"); != "" {
, := .Type().FieldByName()
= .Tag
= elemOf(.FieldByName())
if !.IsValid() {
return nil
}
}
:= NewXMLElement(xml.Name{Local: .Get("locationName")})
if , := .Get("xmlPrefix"), .Get("xmlURI"); != "" {
:= xml.Attr{
Name: xml.Name{Local: "xmlns"},
Value: ,
}
if != "" {
.namespaces[] = // register the namespace
.Name.Local = "xmlns:" +
}
.Attr = append(.Attr, )
}
var , int
:= .Type()
for := 0; < .NumField(); ++ {
:= elemOf(.Field())
:= .Field()
if .PkgPath != "" {
continue // ignore unexported fields
}
if .Tag.Get("ignore") != "" {
continue
}
:= .Tag
if .Get("location") != "" { // skip non-body members
++
continue
}
++
if protocol.CanSetIdempotencyToken(.Field(), ) {
:= protocol.GetIdempotencyToken()
= reflect.ValueOf()
}
:= .Get("locationName")
if == "" {
= .Name
= reflect.StructTag(string() + ` locationName:"` + + `"`)
}
if := .buildValue(, , ); != nil {
return
}
}
:= .Get("flattened") != ""
:= xml.Name{Local: .Get("locationName")}
if {
for := 0; < .Len(); ++ {
:= NewXMLElement()
.AddChild()
if := .buildValue(.Index(), , ""); != nil {
return
}
}
} else {
:= NewXMLElement()
.AddChild()
for := 0; < .Len(); ++ {
:= .Get("locationNameList")
if == "" {
= "member"
}
:= NewXMLElement(xml.Name{Local: })
.AddChild()
if := .buildValue(.Index(), , ""); != nil {
return
}
}
}
return nil
}
func ( *xmlBuilder) ( reflect.Value, *XMLNode, reflect.StructTag) error {
if .IsNil() { // don't build omitted maps
return nil
}
:= NewXMLElement(xml.Name{Local: .Get("locationName")})
.AddChild()
=
, := "key", "value"
if := .Get("locationNameKey"); != "" {
=
}
if := .Get("locationNameValue"); != "" {
=
}
:= make([]string, .Len())
for , := range .MapKeys() {
[] = .String()
}
sort.Strings()
for , := range {
:= .MapIndex(reflect.ValueOf())
:=
if .Get("flattened") == "" { // add "entry" tag to non-flat maps
:= NewXMLElement(xml.Name{Local: "entry"})
.AddChild()
=
}
:= NewXMLElement(xml.Name{Local: })
.Text =
:= NewXMLElement(xml.Name{Local: })
.AddChild()
.AddChild()
if := .buildValue(, , ""); != nil {
return
}
}
return nil
}
func ( *xmlBuilder) ( reflect.Value, *XMLNode, reflect.StructTag) error {
var string
switch converted := .Interface().(type) {
case string:
=
case []byte:
if !.IsNil() {
= base64.StdEncoding.EncodeToString()
}
case bool:
= strconv.FormatBool()
case int64:
= strconv.FormatInt(, 10)
case int:
= strconv.Itoa()
case float64:
= strconv.FormatFloat(, 'f', -1, 64)
case float32:
= strconv.FormatFloat(float64(), 'f', -1, 32)
case time.Time:
:= .Get("timestampFormat")
if len() == 0 {
= protocol.ISO8601TimeFormatName
}
= protocol.FormatTime(, )
default:
return fmt.Errorf("unsupported value for param %s: %v (%s)",
.Get("locationName"), .Interface(), .Type().Name())
}
:= xml.Name{Local: .Get("locationName")}
if .Get("xmlAttribute") != "" { // put into current node's attribute list
:= xml.Attr{Name: , Value: }
.Attr = append(.Attr, )
} else { // regular text node
.AddChild(&XMLNode{Name: , Text: })
}
return nil
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |