Decode / encode XML to/from map[string]interface{} (or JSON); extract values with dot-notation paths and wildcards. Replaces x2j and j2x packages.

Related tags

Data Structures mxj
Overview

mxj - to/from maps, XML and JSON

Decode/encode XML to/from map[string]interface{} (or JSON) values, and extract/modify values from maps by key or key-path, including wildcards.

mxj supplants the legacy x2j and j2x packages. If you want the old syntax, use mxj/x2j and mxj/j2x packages.

Installation

Using go.mod:
go get github.com/clbanning/mxj/[email protected]
import "github.com/clbanning/mxj/v2"

... or just vendor the package.

Related Packages

https://github.com/clbanning/checkxml provides functions for validating XML data.

Refactor Encoder - 2020.05.01

Issue #70 highlighted that encoding large maps does not scale well, since the original logic used string appends operations. Using bytes.Buffer results in linear scaling for very large XML docs. (Metrics based on MacBook Pro i7 w/ 16 GB.)
Nodes      m.XML() time
54809       12.53708ms
109780      32.403183ms
164678      59.826412ms
482598     109.358007ms

Refactor Decoder - 2015.11.15

For over a year I've wanted to refactor the XML-to-map[string]interface{} decoder to make it more performant. I recently took the time to do that, since we were using github.com/clbanning/mxj in a production system that could be deployed on a Raspberry Pi. Now the decoder is comparable to the stdlib JSON-to-map[string]interface{} decoder in terms of its additional processing overhead relative to decoding to a structure value. As shown by:
BenchmarkNewMapXml-4         	  100000	     18043 ns/op
BenchmarkNewStructXml-4      	  100000	     14892 ns/op
BenchmarkNewMapJson-4        	  300000	      4633 ns/op
BenchmarkNewStructJson-4     	  300000	      3427 ns/op
BenchmarkNewMapXmlBooks-4    	   20000	     82850 ns/op
BenchmarkNewStructXmlBooks-4 	   20000	     67822 ns/op
BenchmarkNewMapJsonBooks-4   	  100000	     17222 ns/op
BenchmarkNewStructJsonBooks-4	  100000	     15309 ns/op

Notices

2021.02.02: v2.5 - add XmlCheckIsValid toggle to force checking that the encoded XML is valid
2020.12.14: v2.4 - add XMLEscapeCharsDecoder to preserve XML escaped characters in Map values
2020.10.28: v2.3 - add TrimWhiteSpace option
2020.05.01: v2.2 - optimize map to XML encoding for large XML docs.
2019.07.04: v2.0 - remove unnecessary methods - mv.XmlWriterRaw, mv.XmlIndentWriterRaw - for Map and MapSeq.
2019.07.04: Add MapSeq type and move associated functions and methods from Map to MapSeq.
2019.01.21: DecodeSimpleValuesAsMap - decode to map[<tag>:map["#text":<value>]] rather than map[<tag>:<value>]
2018.04.18: mv.Xml/mv.XmlIndent encodes non-map[string]interface{} map values - map[string]string, map[int]uint, etc.
2018.03.29: mv.Gob/NewMapGob support gob encoding/decoding of Maps.
2018.03.26: Added mxj/x2j-wrapper sub-package for migrating from legacy x2j package.
2017.02.22: LeafNode paths can use ".N" syntax rather than "[N]" for list member indexing.
2017.02.10: SetFieldSeparator changes field separator for args in UpdateValuesForPath, ValuesFor... methods.
2017.02.06: Support XMPP stream processing - HandleXMPPStreamTag().
2016.11.07: Preserve name space prefix syntax in XmlSeq parser - NewMapXmlSeq(), etc.
2016.06.25: Support overriding default XML attribute prefix, "-", in Map keys - SetAttrPrefix().
2016.05.26: Support customization of xml.Decoder by exposing CustomDecoder variable.
2016.03.19: Escape invalid chars when encoding XML attribute and element values - XMLEscapeChars().
2016.03.02: By default decoding XML with float64 and bool value casting will not cast "NaN", "Inf", and "-Inf".
            To cast them to float64, first set flag with CastNanInf(true).
2016.02.22: New mv.Root(), mv.Elements(), mv.Attributes methods let you examine XML document structure.
2016.02.16: Add CoerceKeysToLower() option to handle tags with mixed capitalization.
2016.02.12: Seek for first xml.StartElement token; only return error if io.EOF is reached first (handles BOM).
2015.12.02: XML decoding/encoding that preserves original structure of document. See NewMapXmlSeq()
            and mv.XmlSeq() / mv.XmlSeqIndent().
2015-05-20: New: mv.StringIndentNoTypeInfo().
            Also, alphabetically sort map[string]interface{} values by key to prettify output for mv.Xml(),
            mv.XmlIndent(), mv.StringIndent(), mv.StringIndentNoTypeInfo().
2014-11-09: IncludeTagSeqNum() adds "_seq" key with XML doc positional information.
            (NOTE: PreserveXmlList() is similar and will be here soon.)
2014-09-18: inspired by NYTimes fork, added PrependAttrWithHyphen() to allow stripping hyphen from attribute tag.
2014-08-02: AnyXml() and AnyXmlIndent() will try to marshal arbitrary values to XML.
2014-04-28: ValuesForPath() and NewMap() now accept path with indexed array references.

Basic Unmarshal XML to map[string]interface{}

type Map map[string]interface{}

Create a Map value, 'mv', from any map[string]interface{} value, 'v':

mv := Map(v)

Unmarshal / marshal XML as a Map value, 'mv':

mv, err := NewMapXml(xmlValue) // unmarshal
xmlValue, err := mv.Xml()      // marshal

Unmarshal XML from an io.Reader as a Map value, 'mv':

mv, err := NewMapXmlReader(xmlReader)         // repeated calls, as with an os.File Reader, will process stream
mv, raw, err := NewMapXmlReaderRaw(xmlReader) // 'raw' is the raw XML that was decoded

Marshal Map value, 'mv', to an XML Writer (io.Writer):

err := mv.XmlWriter(xmlWriter)
raw, err := mv.XmlWriterRaw(xmlWriter) // 'raw' is the raw XML that was written on xmlWriter

Also, for prettified output:

xmlValue, err := mv.XmlIndent(prefix, indent, ...)
err := mv.XmlIndentWriter(xmlWriter, prefix, indent, ...)
raw, err := mv.XmlIndentWriterRaw(xmlWriter, prefix, indent, ...)

Bulk process XML with error handling (note: handlers must return a boolean value):

err := HandleXmlReader(xmlReader, mapHandler(Map), errHandler(error))
err := HandleXmlReaderRaw(xmlReader, mapHandler(Map, []byte), errHandler(error, []byte))

Converting XML to JSON: see Examples for NewMapXml and HandleXmlReader.

There are comparable functions and methods for JSON processing.

Arbitrary structure values can be decoded to / encoded from Map values:

mv, err := NewMapStruct(structVal)
err := mv.Struct(structPointer)

Extract / modify Map values

To work with XML tag values, JSON or Map key values or structure field values, decode the XML, JSON or structure to a `Map` value, 'mv', or cast a `map[string]interface{}` value to a `Map` value, 'mv', then:
paths := mv.PathsForKey(key)
path := mv.PathForKeyShortest(key)
values, err := mv.ValuesForKey(key, subkeys)
values, err := mv.ValuesForPath(path, subkeys)
count, err := mv.UpdateValuesForPath(newVal, path, subkeys)

Get everything at once, irrespective of path depth:

leafnodes := mv.LeafNodes()
leafvalues := mv.LeafValues()

A new Map with whatever keys are desired can be created from the current Map and then encoded in XML or JSON. (Note: keys can use dot-notation.)

newMap, err := mv.NewMap("oldKey_1:newKey_1", "oldKey_2:newKey_2", ..., "oldKey_N:newKey_N")
newMap, err := mv.NewMap("oldKey1", "oldKey3", "oldKey5") // a subset of 'mv'; see "examples/partial.go"
newXml, err := newMap.Xml()   // for example
newJson, err := newMap.Json() // ditto

Usage

The package is fairly well self-documented with examples.

Also, the subdirectory "examples" contains a wide range of examples, several taken from golang-nuts discussions.

XML parsing conventions

Using NewMapXml()

  • Attributes are parsed to map[string]interface{} values by prefixing a hyphen, -, to the attribute label. (Unless overridden by PrependAttrWithHyphen(false) or SetAttrPrefix().)
  • If the element is a simple element and has attributes, the element value is given the key #text for its map[string]interface{} representation. (See the 'atomFeedString.xml' test data, below.)
  • XML comments, directives, and process instructions are ignored.
  • If CoerceKeysToLower() has been called, then the resultant keys will be lower case.

Using NewMapXmlSeq()

  • Attributes are parsed to map["#attr"]map[<attr_label>]map[string]interface{}values where the <attr_label> value has "#text" and "#seq" keys - the "#text" key holds the value for <attr_label>.
  • All elements, except for the root, have a "#seq" key.
  • Comments, directives, and process instructions are unmarshalled into the Map using the keys "#comment", "#directive", and "#procinst", respectively. (See documentation for more specifics.)
  • Name space syntax is preserved:
    • <ns:key>something</ns.key> parses to map["ns:key"]interface{}{"something"}
    • xmlns:ns="http://myns.com/ns" parses to map["xmlns:ns"]interface{}{"http://myns.com/ns"}

Both

  • By default, "Nan", "Inf", and "-Inf" values are not cast to float64. If you want them to be cast, set a flag to cast them using CastNanInf(true).

XML encoding conventions

  • 'nil' Map values, which may represent 'null' JSON values, are encoded as <tag/>. NOTE: the operation is not symmetric as <tag/> elements are decoded as tag:"" Map values, which, then, encode in JSON as "tag":"" values.
  • ALSO: there is no guarantee that the encoded XML doc will be the same as the decoded one. (Go randomizes the walk through map[string]interface{} values.) If you plan to re-encode the Map value to XML and want the same sequencing of elements look at NewMapXmlSeq() and mv.XmlSeq() - these try to preserve the element sequencing but with added complexity when working with the Map representation.

Running "go test"

Because there are no guarantees on the sequence map elements are retrieved, the tests have been written for visual verification in most cases. One advantage is that you can easily use the output from running "go test" as examples of calling the various functions and methods.

Motivation

I make extensive use of JSON for messaging and typically unmarshal the messages into map[string]interface{} values. This is easily done using json.Unmarshal from the standard Go libraries. Unfortunately, many legacy solutions use structured XML messages; in those environments the applications would have to be refactored to interoperate with my components.

The better solution is to just provide an alternative HTTP handler that receives XML messages and parses it into a map[string]interface{} value and then reuse all the JSON-based code. The Go xml.Unmarshal() function does not provide the same option of unmarshaling XML messages into map[string]interface{} values. So I wrote a couple of small functions to fill this gap and released them as the x2j package.

Over the next year and a half additional features were added, and the companion j2x package was released to address XML encoding of arbitrary JSON and map[string]interface{} values. As part of a refactoring of our production system and looking at how we had been using the x2j and j2x packages we found that we rarely performed direct XML-to-JSON or JSON-to_XML conversion and that working with the XML or JSON as map[string]interface{} values was the primary value. Thus, everything was refactored into the mxj package.

Issues
  • XmlToMapParser nil error

    XmlToMapParser nil error

    I've encountered a case where 'skey' seems to be empty and golang throws 'panic: assignment to entry in nil map'. Adding a check for 'skey' fixes that.

    opened by adrianlungu 19
  • Reading directly from reader will fail parse, but writing and reading again succeed

    Reading directly from reader will fail parse, but writing and reading again succeed

    When getting the following perfectly valid XML (a response from PANW Wildfire component): ` 2.0 <file_info> yes b918d3b98f590d99ac3694b373958017256a22b4 PE dd8e64991f68eeebb52c9947ea56f39a776185d1a076741533aa6843022c03b0 7f638f13d0797ef9b1a393808dc93b94 55296 </file_info> <task_info> 3.0 2 Windows XP, Adobe Reader 9.4.0, Flash 10, Office 2007 dd8e64991f68eeebb52c9947ea56f39a776185d1a076741533aa6843022c03b0 7f638f13d0797ef9b1a393808dc93b94 55296 yes

    This is a WildFire test sample Created or modified a file in the Windows system folder Created or modified a file Modified the Windows Registry Created Process c:\documents and settings\administrator\sample.exe Set key \REGISTRY\MACHINE\SOFTWARE\PaloAlto\PanCar to value 1 3.0 5 Windows 7 x64 SP1, Adobe Reader 11, Flash 11, Office 2010 dd8e64991f68eeebb52c9947ea56f39a776185d1a076741533aa6843022c03b0 7f638f13d0797ef9b1a393808dc93b94 55296 yes This is a WildFire test sample Created or modified a file Modified the Windows Registry Created Process C:\Users\Administrator\sample.exe Set key \REGISTRY\MACHINE\SOFTWARE\Wow6432Node\PaloAlto\PanCar to value 1 3.0 204 PE Static Analyzer dd8e64991f68eeebb52c9947ea56f39a776185d1a076741533aa6843022c03b0 7f638f13d0797ef9b1a393808dc93b94 no Contains an invalid checksum Contains sections with size discrepancies ` And using the following function: `func ParseXMLResponseToJSON(reader io.Reader, resEntry *domain.Entry) error { b, err := ioutil.ReadAll(reader) if err != nil { return err } fmt.Println(string(b)) reader = bytes.NewReader(b) m, err := mxj.NewMapXmlReader(reader) if err != nil { return err } content, err := json.Marshal(m) if err != nil { return err } return string(content) }` I get the response in json. However, when I read direcly from the reader: `func ParseXMLResponseToJSON(reader io.Reader, resEntry *domain.Entry) error { /*b, err := ioutil.ReadAll(reader) if err != nil { return err } fmt.Println(string(b))*/ reader = bytes.NewReader(b) m, err := mxj.NewMapXmlReader(reader) if err != nil { return err } content, err := json.Marshal(m) if err != nil { return err } return string(content)` I get the following error: `xml.Decoder.Token() - XML syntax error on line 135: unexpected EOF`
    opened by Spivaka 11
  • Xml serialization time grows exponentially with size of map

    Xml serialization time grows exponentially with size of map

    map.Xml() time grows exponentially for large map. For example if we read 1MB XML and serialize it back it take almost 20s and if we double the size (duplicate the xml nodes from same input) then time taken is almost 90s.

    I tested with this xml (http://aiweb.cs.washington.edu/research/projects/xmltk/xmldata/data/mondial/mondial-3.0.xml) with following code.

    package main
    
    import (
    	"fmt"
    	"io/ioutil"
    	"time"
    
    	mxj "github.com/clbanning/mxj"
    )
    
    func main() {
    	b, _ := ioutil.ReadFile("/tmp/large.xml")
    	start := time.Now()
    	m, _ := mxj.NewMapXml(b)
    	fmt.Printf("XML Read time %v\n", time.Now().Sub(start))
    	start = time.Now()
    	b, _ = m.Xml()
    	fmt.Printf("XML Write time %v\n", time.Now().Sub(start))
    }
    

    I debugged further and I think it is because of string concatenation (*s += ). I created a simple code to string concatenation and found that it is very slow as string grows. When I replaced it by bytes.Buffer.Read then there was significant improvement.

    opened by nadddy 10
  • getSubKeyMap

    getSubKeyMap

    There seems to be a couple issues with this function.

    Getting a runtime error: index out of range [recovered] First the switch is on the length of the split string. If the length of the string array is 3 (case 3), then you can't reference vv[3] which would be the 4th element right? It must be vv[2] to access the third string.

    Second, if your text has any ":" in it, it will get confused. My text had a "http://blah/blah/blah" in it. So, after I made the above change, I got the error: "unknown subkey conversion spec:..."

    Basically I was trying to read in a kml file, change the description and name fields and then print it back out. I was trying to use the paths= PathsForKey("description") values =ValuesForPath(paths[0]).
    UpdateValuesForPath(newVal, path[0], "description:"+value[0]) with a double loop in there to get all the paths and values. But, because description can have any kind of text, this will not be possible. Is there a better way of doing this?

    Thanks, Lorie

    opened by lorie131 10
  • NewMapXmlSeq process instructions

    NewMapXmlSeq process instructions

    hi,

    I'm dealing with some XML files that have <?xml version="1.0" encoding="utf-8"?> at top of the file by using the NewMapXmlSeq cause I want to preserve the format and some comments in the file.

    But I could only get the result map[#procinst:map[#target:xml #inst:version="1.0" encoding="utf-8"]], and the returned error is no root key

    As you mentioned in the doc:

    comments, directives, and procinsts that are NOT part of a document with a root key will be returned as
      map[string]interface{} and the error value 'NoRoot'.
    

    How can I get the whole map of the XML file? I thought it's quite common that <?xml version="1.0" encoding="utf-8"?> not belong to any root

    opened by s850042002 8
  • [Bug]integer will be transformed to double

    [Bug]integer will be transformed to double

    Input json: "ipv4": { "address-mode": "manual", "address": { "ip": "10.10.10.10", "prefix-length": 30 }

    Output xml: <ipv4><address><ip>10.0.22.14</ip><prefix-length>30.000000</prefix-length></address><address-mode>manual</address-mode><enabled>true</enabled><mtu>1500.000000</mtu><vti_peer>10.10.10.10</vti_peer></ipv4>

    In this case, prefix-length:30 became 30.000000 Do anyone have the same problem with me?

    opened by chenYunHsin-maker 7
  • XmlWriter produces formally incorrect XML

    XmlWriter produces formally incorrect XML

    But it should not, of course. E.g. serializing this mxj-map

            m[""] = "empty"
    	m["$invalid"] = "hex$"
    	m["entities"] = "<>&"
    	m["nil"] = nil
    

    produces this string, which is formally incorrect XML:

    <root>
      <>empty</>
      <$invalid>hex$</$invalid>
      <entities><>&</entities>
      <nil><nil></nil>
    </root>
    

    Errors are:

    • <> is not a valid XML element
    • $ is not valid in XML element names
    • the three basic XML entities <, > and & must be escaped as &lt;, &gt; and &amp;
    • the nil interface{} value is serialized as <nil> without escaping < and >

    Additionally there are some decisions to be drawn for how to mitigate these problems. Probably some strategies need to be implemented for a client to customize the behavior of the API

    • empty element names should either be omitted or given a customizeable name
    • invalid element name characters could be either dropped completely or somehow encoded by valid entity characters like a hex string representation decorated with the valid _ char
    • nil valued elements could be serialized as <element-name/>, <element-name></element-name>, omitted, or marked with xsi:nil="true" (see e.g. https://www.oreilly.com/library/view/xml-in-a/0596007647/re166.html)

    test fixture (example)

    package web
    
    import (
    	"bytes"
    	"testing"
    
    	"github.com/clbanning/mxj/v2"
    )
    
    func TestJSON2XMLConverter(t *testing.T) {
    	m := mxj.New()
    
    	m[""] = "empty"
    	m["$invalid"] = "hex$"
    	m["entities"] = "<>&"
    	m["nil"] = nil
    
    	buf := new(bytes.Buffer)
    	err := m.XmlWriter(buf, "root")
    	if err != nil {
    		t.Fatalf("writer: %v", err)
    	}
    
    	if got, want := buf.String(), `<root><_24_invalid>hex$</_24_invalid><entities>&lt;&gt;&amp;</entities><nil></nil></root>`; got != want {
    		// want <root><_>empty</_><_24_invalid>hex$</_24_invalid><entities>&lt;&gt;&amp;</entities><nil></nil></root>
    		// got <root><>empty</><$invalid>hex$</$invalid><entities><>&</entities><nil><nil></nil></root>
    		t.Errorf("want %v, got %v", want, got)
    	}
    }
    
    opened by Lercher 6
  • When marshal with map[string]string, it gave me UNKNOWN/>"">

    When marshal with map[string]string, it gave me ">UNKNOWN/>"

    Hi there, mxj is a great project and I've been using it in my gf project in XML marshal/unmarshal. It worked quite well with map[string]interface{} type, but when the parameter contains other map type (eg: map[string]string/map[string]int etc...), it failed working.

    Here's the simple codes to reproduce this issue:

    package main
    
    import (
        "fmt"
        "github.com/clbanning/mxj"
    )
    
    func main() {
        m := make(map[string]interface{})
        m["m"] = map[string]string {
            "k" : "v",
        }
        b, _ := mxj.Map(m).Xml()
        fmt.Println(string(b))
    }
    

    It's supposed to give me {"m":{"k":"v"}}, but actually I got >UNKNOWN/>.

    Would you please take a look, and kindly give me a nice feedback, thanks!

    opened by gqcn 6
  • Inner Tag Ordering

    Inner Tag Ordering

    Is there any way to get the ordering of inner tags, if they are variable in their tag name?

    For example:

    Obj Attr3 Attr1 Attr2 Obj

    This ends up a map

    {Obj:{Attr1:"",Attr2:"",Attr3:""}}, and there is no way to tell that the order was 3,1,2. I've run into a situation where I need to know the order, is there some flag or something that would allow me to turn the attributes into an ordered array, or to write out the order the parser ran into them as an attribute or something?

    opened by murphysean 6
  • NewMapXml truncate html tag content

    NewMapXml truncate html tag content

    Using NewMapXml with data that contains HTML tags results in truncated output.

    package main
    
    import (
     "fmt"
    
     "github.com/clbanning/mxj"
    )
    
    func main() {
     bytes := []byte(`<?xml version="1.0"?>
    <article>
    	<body>
        		<p>hello world<b>truncate me</b></p>
    	</body>
    </article>`)
    
     m, err := mxj.NewMapXml(bytes)
     if err != nil {
      fmt.Println("err:", err)
      return
     }
     fmt.Println("mxj.Map:\n",m.StringIndent(3))
    
     mxj.XMLEscapeChars(false)
     v, err := m.Xml()
     if err != nil {
      fmt.Println("err:", err)
      return
     }
     fmt.Println("\nm.Xml:\n", string(v))
    }
    
    mxj.Map:
           article : 
            body : 
              p : [string] hello world
    
    m.Xml:
     <article><body><p>hello world</p></body></article>
    

    The expected behaviour could be to leave the content as it is without the truncation. @clbanning what do you think?

    opened by salimane 5
  • Unexpected handling of entities

    Unexpected handling of entities

    Using NewMapXml with data that contains entities (e.g. &lt;) results in unexpected output.

    bytes := []byte(`<?xml version="1.0"?>
    <systemList>
      <system>
        <name>retropie</name>
        <fullname>RetroPie</fullname>
        <path>/home/fozz/RetroPie/retropiemenu</path>
        <extension>.rp .sh</extension>
        <command>sudo /home/fozz/RetroPie-Setup/retropie_packages.sh retropiemenu launch %ROM% &lt;/dev/tty &gt;/dev/tty</command>
        <platform/>
        <theme>retropie</theme>
      </system>
    </systemList>`)
    
    val, _ := mxj.NewMapXml(bytes)
    
    // Print val["systemList"]["system"]["command"]
    
    fmt.Println(val["systemList"].(map[string]interface{})["system"].(map[string]interface{})["command"])
    
    //  sudo /home/fozz/RetroPie-Setup/retropie_packages.sh retropiemenu launch %ROM% </dev/tty >/dev/tty
    

    I expected the value of systemList > system > command to be: sudo /home/fozz/RetroPie-Setup/retropie_packages.sh retropiemenu launch %ROM% &lt;/dev/tty &gt;/dev/tty

    But I can see that it's actual value is: sudo /home/fozz/RetroPie-Setup/retropie_packages.sh retropiemenu launch %ROM% </dev/tty >/dev/tty

    opened by TomWright 5
  • issue with reading req.Body / res.Body directly

    issue with reading req.Body / res.Body directly

    Hello!

    First, thank you for such a great project!

    I found a small issue when reading req.Body & res.Body, that was already reported at #38. I looked for the commit that changed it back and it's this one: https://github.com/clbanning/mxj/commit/dc2e2f9bad3281f541a09f6e0aa17e49872d3515

    Reading through net/http code I see that the only difference is that it uses io.NopCloser in NewRequest, which is what causes the problem mentioned in #38.

    After further investigation, I noticed something: io.NopCloser does not implement ReadByte, which make we fallback to the implementation that is found here in mxj.

    I found this issue because I had to make some cleanup to a http.Response.Body and wrapped the returned reader (which probably is a *bufio.Reader) with my custom one, causing the issue mentioned in #38.

    As the change made in #38 was rolled back, I'm not sure which is the best fix to the current byteReader implementation though, which is why I am only opening a issue and not a PR.

    Again, thank you for the great project!

    Sample code reproducing the mentioned issue: https://go.dev/play/p/ffJvzhYD1h1

    opened by brenol 0
Releases(v2.5.6)
Owner
Charles Banning
Charles Banning
A Blurhash implementation in pure Go (Decode/Encode)

go-blurhash go-blurhash is a pure Go implementation of the BlurHash algorithm, which is used by Mastodon an other Fediverse software to implement a sw

buckket 146 Jun 17, 2022
An in-memory string-interface{} map with various expiration options for golang

TTLCache - an in-memory cache with expiration TTLCache is a simple key/value cache in golang with the following functions: Expiration of items based o

Rene Kroon 442 Jun 25, 2022
An in-memory string-interface{} map with various expiration options for golang

TTLCache - an in-memory cache with expiration TTLCache is a simple key/value cache in golang with the following functions: Expiration of items based o

Rene Kroon 442 Jun 25, 2022
Go library for encoding native Go structures into generic map values.

wstructs origin: github.com/things-go/structs Go library for encoding native Go structures into generic map values. Installation Use go get. go ge

null 0 Jan 10, 2022
skipmap is a high-performance concurrent sorted map based on skip list. Up to 3x ~ 10x faster than sync.Map in the typical pattern.

Introduction skipmap is a high-performance concurrent map based on skip list. In typical pattern(one million operations, 90%LOAD 9%STORE 1%DELETE), th

ZhangYunHao 66 Jul 2, 2022
A fast (5x) string keyed read-only map for Go - particularly good for keys using a small set of nearby runes.

faststringmap faststringmap is a fast read-only string keyed map for Go (golang). For our use case it is approximately 5 times faster than using Go's

The Sensible Code Company 27 Jun 23, 2022
Dasel - Select, put and delete data from JSON, TOML, YAML, XML and CSV files with a single tool.

Select, put and delete data from JSON, TOML, YAML, XML and CSV files with a single tool. Supports conversion between formats and can be used as a Go package.

Tom Wright 3.3k Jun 24, 2022
Convert json string to Golang struct

json-to-go-cli Convert json string to Golang struct How to install git clone https://github.com/tiancheng92/json-to-go-cli.git cd json-to-go-cli go bu

TianCheng 7 May 10, 2022
parse and generate XML easily in go

etree The etree package is a lightweight, pure go package that expresses XML in the form of an element tree. Its design was inspired by the Python Ele

Brett Vickers 967 Jul 2, 2022
Converts PDF, DOC, DOCX, XML, HTML, RTF, etc to plain text

docconv A Go wrapper library to convert PDF, DOC, DOCX, XML, HTML, RTF, ODT, Pages documents and images (see optional dependencies below) to plain tex

Search.io 959 Jun 23, 2022
Go package for mapping values to and from space-filling curves, such as Hilbert and Peano curves.

Hilbert Go package for mapping values to and from space-filling curves, such as Hilbert and Peano curves. Documentation available here This is not an

Google 252 Jun 20, 2022
💯 Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving

Package validator implements value validations for structs and individual fields based on tags.

Flamego 12 Feb 16, 2022
Convert Go values to their AST

valast - convert Go values to their AST Valast converts Go values at runtime into their go/ast equivalent,

Hexops 257 Jun 10, 2022
Enforce default values on structs in Go

Defaults Enforce default values on struct fields. type User struct { Name string `default:"Goku"` Power float64 `default:"9000.01"` } var u

Christian Rocha 22 Jun 15, 2022
Print Go values as Go source.

printsrc: Printing Go Values as Source There are many packages that print Go values so people can read them. This package prints Go values so the Go c

Jonathan Amsterdam 12 Dec 27, 2021
A thread safe map which has expiring key-value pairs

~ timedmap ~ A map which has expiring key-value pairs. go get github.com/zekroTJA/timedmap Intro This package allows to set values to a map which will

zekro 42 May 25, 2022
A prefix-enhanced map in Go

PrefixMap PrefixMap is a prefix-enhanced map that eases the retrieval of values based on key prefixes. Quick Start Creating a PrefixMap // creates the

Alessandro Diaferia 30 Jun 13, 2022
A typed implementation of the Go sync.Map using code generation

syncmap A typed implementation of the Go sync.Map using code generation. Install go get -u github.com/a8m/[email protected] Examples: Using CLI $ syncma

Ariel Mashraki 233 Jun 30, 2022
A Go library to iterate over potentially nested map keys using the visitor pattern

A Go library to iterate over potentially nested map keys using the visitor pattern

null 3 Mar 15, 2022