123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package myth
- import (
- "encoding/json"
- "encoding/xml"
- )
- const (
- _ = iota
- // KB kilo byte
- KB int = 1 << (10 * iota)
- // MB mega byte
- MB
- // GB giga byte
- GB
- // TB tera byte
- TB
- // PB peta byte
- PB
- )
- // Map is a shortcut for map[string]interface{}
- type Map map[string]interface{}
- // String map to json string
- func (m Map) String() string {
- bs, _ := json.Marshal(m)
- return string(bs)
- }
- // Bytes map to json bytes
- func (m Map) Bytes() []byte {
- bs, _ := json.Marshal(m)
- return bs
- }
- // MarshalXML allows type Map to be used with xml.Marshal.
- func (m Map) 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 m {
- elem := xml.StartElement{
- Name: xml.Name{Space: "", Local: key},
- Attr: []xml.Attr{},
- }
- if err := e.EncodeElement(value, elem); err != nil {
- return err
- }
- }
- return e.EncodeToken(xml.EndElement{Name: start.Name})
- }
|