12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package myth
- import (
- "encoding/json"
- "encoding/xml"
- )
- const (
- _ = iota
-
- KB int = 1 << (10 * iota)
-
- MB
-
- GB
-
- TB
-
- PB
- )
- type M map[string]any
- func NewM() M {
- return make(map[string]any)
- }
- func (m M) Set(k string, v any) {
- m[k] = v
- }
- func (m M) Get(k string) (v any, ok bool) {
- v, ok = m[k]
- return
- }
- func (m M) String() string {
- bs, _ := json.Marshal(m)
- return string(bs)
- }
- func (m M) Bytes() []byte {
- bs, _ := json.Marshal(m)
- return bs
- }
- func (m M) 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})
- }
|