Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const Format = "xml"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Marshaller ¶
type Marshaller struct {
}
func (Marshaller) Marshal ¶
func (Marshaller) Marshal(in interface{}, variable model.ContentVariable) (out string, err error)
Example ¶
value := map[string]interface{}{"-attr": "attrVal", "body": "bodyVal"}
marshaller, ok := base.Get(Format)
if !ok {
return
}
fmt.Println(marshaller.Marshal(value, model.ContentVariable{
Name: "example",
Type: model.Structure,
SubContentVariables: []model.ContentVariable{
{Name: "-attr"},
{Name: "body"},
},
}))
Output: <example attr="attrVal"><body>bodyVal</body></example> <nil>
Example (PrimitiveBool) ¶
value := true
marshaller, ok := base.Get(Format)
if !ok {
return
}
fmt.Println(marshaller.Marshal(value, model.ContentVariable{
Name: "b",
}))
Output: <b>true</b> <nil>
Example (PrimitiveFloat) ¶
value := 2.4
marshaller, ok := base.Get(Format)
if !ok {
return
}
fmt.Println(marshaller.Marshal(value, model.ContentVariable{
Name: "f",
}))
Output: <f>2.4</f> <nil>
Example (PrimitiveInt) ¶
value := 24
marshaller, ok := base.Get(Format)
if !ok {
return
}
fmt.Println(marshaller.Marshal(value, model.ContentVariable{
Name: "int",
}))
Output: <int>24</int> <nil>
Example (PrimitiveString) ¶
value := "foo"
marshaller, ok := base.Get(Format)
if !ok {
return
}
fmt.Println(marshaller.Marshal(value, model.ContentVariable{
Name: "str",
}))
Output: <str>foo</str> <nil>
Example (SerializationOptionXmlAttribute) ¶
value := map[string]interface{}{"attr": "attrVal", "body": "bodyVal"}
marshaller, ok := base.Get(Format)
if !ok {
return
}
fmt.Println(marshaller.Marshal(value, model.ContentVariable{
Name: "example",
Type: model.Structure,
SubContentVariables: []model.ContentVariable{
{Name: "attr", SerializationOptions: []string{models.SerializationOptionXmlAttribute}},
{Name: "body"},
},
}))
Output: <example attr="attrVal"><body>bodyVal</body></example> <nil>
func (Marshaller) Unmarshal ¶
func (Marshaller) Unmarshal(in string, variable model.ContentVariable) (out interface{}, err error)
Click to show internal directories.
Click to hide internal directories.