From fe025941a954e8d61086d0d9589a87466ce01dcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?p=C3=A9riode?= Date: Fri, 27 May 2022 01:02:24 +0200 Subject: [PATCH 01/28] added named struct extraction flag --- cmd/zek/main.go | 2 ++ structwriter.go | 93 +++++++++++++++++++++++++++++-------------------- 2 files changed, 57 insertions(+), 38 deletions(-) diff --git a/cmd/zek/main.go b/cmd/zek/main.go index 90102fc..1fb4102 100644 --- a/cmd/zek/main.go +++ b/cmd/zek/main.go @@ -23,6 +23,7 @@ var ( debug = flag.Bool("d", false, "debug output") createExampleProgram = flag.Bool("p", false, "write out an example program") tagName = flag.String("t", "", "emit struct for tag matching this name") + replaceStructs = flag.String("r", "", "replace anonymous structs by tags matching this name, e.g. 'name1 name2'") skipFormatting = flag.Bool("F", false, "skip formatting") strict = flag.Bool("s", false, "strict parsing and writing") exampleMaxChars = flag.Int("x", 25, "max chars for example") @@ -99,6 +100,7 @@ func main() { sw.Strict = *strict sw.ExampleMaxChars = *exampleMaxChars sw.Compact = !*nonCompact + sw.ReplaceStruct = strings.Split(*replaceStructs, " ") sw.UniqueExamples = *uniqueExamples sw.OmitEmptyText = *omitEmptyText if *fixedBanner { diff --git a/structwriter.go b/structwriter.go index ece6f37..0f5c1ba 100644 --- a/structwriter.go +++ b/structwriter.go @@ -100,6 +100,7 @@ type StructWriter struct { Strict bool // Whether to ignore implementation holes. WithJSONTags bool // Include JSON struct tags. Compact bool // Emit more compact struct. + ReplaceStruct []string // Replaces anonymous struct for into a named struct of the same name UniqueExamples bool // Filter out duplicated examples OmitEmptyText bool // Don't generate Text fields if no example elements have chardata. } @@ -242,53 +243,69 @@ func (sw *StructWriter) writeNode(node *Node, top bool) (err error) { fmt.Fprintf(sew, "%s\n", s) return err } - io.WriteString(sew, "struct {\n") - if top { - sw.writeNameField(sew, node) - } - if !sw.OmitEmptyText || len(node.Examples) > 0 { - sw.writeChardataField(sew, node) + + var namedStruct string + + if !top { + for _, s := range sw.ReplaceStruct { + if s == sw.NameFunc(node.Name.Local) { + namedStruct = s + } + } } - // Helper to check for name clash of attribute with any generated field name. - isValidName := func(name string) bool { - if name == sw.TextFieldNames[0] { - return false + + if namedStruct == "" { + io.WriteString(sew, "struct {\n") + if top { + sw.writeNameField(sew, node) } - for _, child := range node.Children { - if name == sw.NameFunc(child.Name.Local) { + if !sw.OmitEmptyText || len(node.Examples) > 0 { + sw.writeChardataField(sew, node) + } + // Helper to check for name clash of attribute with any generated field name. + isValidName := func(name string) bool { + if name == sw.TextFieldNames[0] { return false } - } - return true - } - // Write attributes. XXX: Better handling of duplicate attributes. - written := make(map[string]bool) - for _, attr := range node.Attr { - name := sw.NameFunc(attr.Name.Local) - for _, prefix := range sw.AttributePrefixes { - if isValidName(name) { - break + for _, child := range node.Children { + if name == sw.NameFunc(child.Name.Local) { + return false + } } - name = fmt.Sprintf("%s%s", prefix, name) - } - if !isValidName(name) { - return fmt.Errorf("name clash: %s", attr.Name.Local) + return true } - if _, ok := written[attr.Name.Local]; ok { - if sw.Strict { - log.Fatalf("[not implemented] duplicate local attribute name: %s", attr) - } else { - log.Printf("warning: duplicate local attribute name: %s", attr) + // Write attributes. XXX: Better handling of duplicate attributes. + written := make(map[string]bool) + for _, attr := range node.Attr { + name := sw.NameFunc(attr.Name.Local) + for _, prefix := range sw.AttributePrefixes { + if isValidName(name) { + break + } + name = fmt.Sprintf("%s%s", prefix, name) + } + if !isValidName(name) { + return fmt.Errorf("name clash: %s", attr.Name.Local) } - continue + if _, ok := written[attr.Name.Local]; ok { + if sw.Strict { + log.Fatalf("[not implemented] duplicate local attribute name: %s", attr) + } else { + log.Printf("warning: duplicate local attribute name: %s", attr) + } + continue + } + sw.writeAttrField(sew, name, "string", attr) + written[attr.Name.Local] = true } - sw.writeAttrField(sew, name, "string", attr) - written[attr.Name.Local] = true - } - for _, child := range node.Children { - sw.writeNode(child, false) + for _, child := range node.Children { + sw.writeNode(child, false) + } + io.WriteString(sew, "} ") + } else { + io.WriteString(sew, namedStruct+" ") } - io.WriteString(sew, "} ") + if !top { sw.writeStructTag(sew, node) } From 58e68f1dae16ecc645ac0eaf6a33b7015fd1d0ff Mon Sep 17 00:00:00 2001 From: Yaroslav Podorvanov Date: Tue, 23 Aug 2022 21:05:55 +0300 Subject: [PATCH 02/28] Opensource wasm alternative https://xml-to-go.github.io/ --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0389271..a4a1884 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,8 @@ type Rss struct { ## Online -Try it online at [https://www.onlinetool.io/xmltogo/](https://www.onlinetool.io/xmltogo/) -- thanks, [kjk](https://github.com/kjk)! +* Try it online at [https://www.onlinetool.io/xmltogo/](https://www.onlinetool.io/xmltogo/) -- thanks, [kjk](https://github.com/kjk)! +* Opensource wasm alternative [https://xml-to-go.github.io/](https://xml-to-go.github.io/) ## About From bb6b75aa7eeb03939cc8a4cbea164246e7bdb75f Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Wed, 14 Sep 2022 17:13:26 +0200 Subject: [PATCH 03/28] update deps --- go.mod | 6 ++---- go.sum | 22 +++++++--------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index e85cd95..849c75f 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,6 @@ module github.com/miku/zek go 1.12 require ( - github.com/sethgrid/pester v0.0.0-20190127155807-68a33a018ad0 - golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 // indirect - golang.org/x/net v0.0.0-20210917221730-978cfadd31cf - golang.org/x/text v0.3.7 // indirect + github.com/sethgrid/pester v1.2.0 + golang.org/x/net v0.0.0-20220909164309-bea034e7d591 ) diff --git a/go.sum b/go.sum index 6816a97..848e037 100644 --- a/go.sum +++ b/go.sum @@ -1,18 +1,10 @@ -github.com/sethgrid/pester v0.0.0-20190127155807-68a33a018ad0 h1:X9XMOYjxEfAYSy3xK1DzO5dMkkWhs9E9UCcS1IERx2k= -github.com/sethgrid/pester v0.0.0-20190127155807-68a33a018ad0/go.mod h1:Ad7IjTpvzZO8Fl0vh9AzQ+j/jYZfyp2diGwI8m5q+ns= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0= -golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210917221730-978cfadd31cf h1:R150MpwJIv1MpS0N/pc+NhTM8ajzvlmxlY5OYsrevXQ= -golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +github.com/sethgrid/pester v1.2.0 h1:adC9RS29rRUef3rIKWPOuP1Jm3/MmB6ke+OhE5giENI= +github.com/sethgrid/pester v1.2.0/go.mod h1:hEUINb4RqvDxtoCaU0BNT/HV4ig5kfgOasrf1xcvr0A= +golang.org/x/net v0.0.0-20220909164309-bea034e7d591 h1:D0B/7al0LLrVC8aWF4+oxpv/m8bc7ViFfVS8/gXGdqI= +golang.org/x/net v0.0.0-20220909164309-bea034e7d591/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= From a56b3a875d890b581a4bc94872c3c21e684363a6 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Mon, 9 Jan 2023 10:37:11 +0100 Subject: [PATCH 04/28] update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a4a1884..750d344 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ Downsides: * experimental, early, buggy, unstable prototype, * no support for recursive types (similar to *Russian Doll* strategy, [[1](https://medbiq.org/std_specs/techguidelines/xmldesignguidelines.pdf#page=7)]) -* no type inference, everything is accessible as string. +* no type inference, everything is accessible as string (without a schema, type inference may fail if the type *guess* is wrong) Bugs: From 9ddf8d30a69190ee6eceb47be0fda45bf99bba3a Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Tue, 17 Jan 2023 12:40:43 +0100 Subject: [PATCH 05/28] add related project --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 750d344..c39a9b0 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,7 @@ Related projects: * https://github.com/bemasher/JSONGen * https://github.com/dutchcoders/XMLGen * https://github.com/gnewton/chidley +* https://github.com/twpayne/go-xmlstruct And other [awesome XML utilities](https://github.com/avelino/awesome-go#xml). From 70ef6b43afba0cc553afff51cc573a95452dccf1 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Mon, 24 Oct 2022 17:58:36 +0200 Subject: [PATCH 06/28] update deps --- go.mod | 2 +- go.sum | 29 +++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 849c75f..c29992a 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,5 @@ go 1.12 require ( github.com/sethgrid/pester v1.2.0 - golang.org/x/net v0.0.0-20220909164309-bea034e7d591 + golang.org/x/net v0.1.0 ) diff --git a/go.sum b/go.sum index 848e037..ebb844f 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,31 @@ github.com/sethgrid/pester v1.2.0 h1:adC9RS29rRUef3rIKWPOuP1Jm3/MmB6ke+OhE5giENI= github.com/sethgrid/pester v1.2.0/go.mod h1:hEUINb4RqvDxtoCaU0BNT/HV4ig5kfgOasrf1xcvr0A= -golang.org/x/net v0.0.0-20220909164309-bea034e7d591 h1:D0B/7al0LLrVC8aWF4+oxpv/m8bc7ViFfVS8/gXGdqI= -golang.org/x/net v0.0.0-20220909164309-bea034e7d591/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0= +golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From 395c64df9b077c541007d9eb18034959508b990b Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Mon, 24 Oct 2022 17:58:55 +0200 Subject: [PATCH 07/28] v0.1.17 --- Makefile | 2 +- packaging/deb/control.amd64 | 2 +- packaging/deb/control.any | 2 +- packaging/deb/zek/DEBIAN/control | 2 +- packaging/rpm/zek.spec | 2 +- version.go | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 4dc4163..4f34b04 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ SHELL = /bin/bash TARGETS = zek PKGNAME = zek ARCH = amd64 -VERSION = 0.1.16 +VERSION = 0.1.17 .PHONY: all all: $(TARGETS) diff --git a/packaging/deb/control.amd64 b/packaging/deb/control.amd64 index 9ead8fa..099b200 100644 --- a/packaging/deb/control.amd64 +++ b/packaging/deb/control.amd64 @@ -1,5 +1,5 @@ Package: zek -Version: 0.1.16 +Version: 0.1.17 Section: utils Priority: optional Architecture: amd64 diff --git a/packaging/deb/control.any b/packaging/deb/control.any index 0524882..3a498a0 100644 --- a/packaging/deb/control.any +++ b/packaging/deb/control.any @@ -1,5 +1,5 @@ Package: zek -Version: 0.1.16 +Version: 0.1.17 Section: utils Priority: optional Architecture: any diff --git a/packaging/deb/zek/DEBIAN/control b/packaging/deb/zek/DEBIAN/control index 9ead8fa..099b200 100644 --- a/packaging/deb/zek/DEBIAN/control +++ b/packaging/deb/zek/DEBIAN/control @@ -1,5 +1,5 @@ Package: zek -Version: 0.1.16 +Version: 0.1.17 Section: utils Priority: optional Architecture: amd64 diff --git a/packaging/rpm/zek.spec b/packaging/rpm/zek.spec index 5ab0deb..38f3a5d 100644 --- a/packaging/rpm/zek.spec +++ b/packaging/rpm/zek.spec @@ -1,6 +1,6 @@ Summary: Generate a Go struct from an XML document. Name: zek -Version: 0.1.16 +Version: 0.1.17 Release: 0 License: GPL BuildArch: x86_64 diff --git a/version.go b/version.go index 5b8741e..e2a3643 100644 --- a/version.go +++ b/version.go @@ -22,4 +22,4 @@ package zek // Version of application. -const Version = "0.1.16" +const Version = "0.1.17" From b403fd39d2df144e7beb1fd393db95e7cff63289 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Tue, 21 Feb 2023 11:28:50 +0100 Subject: [PATCH 08/28] update deps --- go.mod | 2 +- go.sum | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index c29992a..98e5648 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,5 @@ go 1.12 require ( github.com/sethgrid/pester v1.2.0 - golang.org/x/net v0.1.0 + golang.org/x/net v0.7.0 ) diff --git a/go.sum b/go.sum index ebb844f..d48cc6d 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0= golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= +golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -17,14 +19,18 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= From d501f2a69408b54211f5743b9e785d960eda4e72 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Tue, 21 Feb 2023 11:30:02 +0100 Subject: [PATCH 09/28] v0.1.18 --- Makefile | 2 +- packaging/deb/control.amd64 | 2 +- packaging/deb/control.any | 2 +- packaging/deb/zek/DEBIAN/control | 2 +- packaging/rpm/zek.spec | 2 +- version.go | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 4f34b04..4791d09 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ SHELL = /bin/bash TARGETS = zek PKGNAME = zek ARCH = amd64 -VERSION = 0.1.17 +VERSION = 0.1.18 .PHONY: all all: $(TARGETS) diff --git a/packaging/deb/control.amd64 b/packaging/deb/control.amd64 index 099b200..c38933b 100644 --- a/packaging/deb/control.amd64 +++ b/packaging/deb/control.amd64 @@ -1,5 +1,5 @@ Package: zek -Version: 0.1.17 +Version: 0.1.18 Section: utils Priority: optional Architecture: amd64 diff --git a/packaging/deb/control.any b/packaging/deb/control.any index 3a498a0..3662082 100644 --- a/packaging/deb/control.any +++ b/packaging/deb/control.any @@ -1,5 +1,5 @@ Package: zek -Version: 0.1.17 +Version: 0.1.18 Section: utils Priority: optional Architecture: any diff --git a/packaging/deb/zek/DEBIAN/control b/packaging/deb/zek/DEBIAN/control index 099b200..c38933b 100644 --- a/packaging/deb/zek/DEBIAN/control +++ b/packaging/deb/zek/DEBIAN/control @@ -1,5 +1,5 @@ Package: zek -Version: 0.1.17 +Version: 0.1.18 Section: utils Priority: optional Architecture: amd64 diff --git a/packaging/rpm/zek.spec b/packaging/rpm/zek.spec index 38f3a5d..d4dcf3e 100644 --- a/packaging/rpm/zek.spec +++ b/packaging/rpm/zek.spec @@ -1,6 +1,6 @@ Summary: Generate a Go struct from an XML document. Name: zek -Version: 0.1.17 +Version: 0.1.18 Release: 0 License: GPL BuildArch: x86_64 diff --git a/version.go b/version.go index e2a3643..3cb31db 100644 --- a/version.go +++ b/version.go @@ -22,4 +22,4 @@ package zek // Version of application. -const Version = "0.1.17" +const Version = "0.1.18" From 54000d0a8d7f5589c2f5c14f9bfcd268df0a60cd Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Tue, 21 Feb 2023 11:41:46 +0100 Subject: [PATCH 10/28] update go.sum --- go.sum | 6 ------ 1 file changed, 6 deletions(-) diff --git a/go.sum b/go.sum index d48cc6d..b3c256e 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,6 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0= -golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -18,17 +16,13 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= From 9eb19804cbd9bedf928e8b30d62263b68ac65dd1 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Tue, 14 Mar 2023 09:50:04 +0100 Subject: [PATCH 11/28] update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c39a9b0..8f03b1f 100644 --- a/README.md +++ b/README.md @@ -78,8 +78,8 @@ type Rss struct { ## Online -* Try it online at [https://www.onlinetool.io/xmltogo/](https://www.onlinetool.io/xmltogo/) -- thanks, [kjk](https://github.com/kjk)! -* Opensource wasm alternative [https://xml-to-go.github.io/](https://xml-to-go.github.io/) +* Try online via WASM: [https://xml-to-go.github.io/](https://xml-to-go.github.io/), thanks [YaroslavPodorvanov](https://github.com/YaroslavPodorvanov)! +* ([offline as of 03/2022](http://web.archive.org/web/20230000000000*/https://onlinetool.io/xmltogo/)) -- try it online at [https://www.onlinetool.io/xmltogo/](https://www.onlinetool.io/xmltogo/) -- thanks, [kjk](https://github.com/kjk)! ## About From 23bc7e77e5e63837cc10c007d3f6ff136ac8e83c Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Mon, 20 Mar 2023 17:00:51 +0100 Subject: [PATCH 12/28] update link --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8f03b1f..b894e47 100644 --- a/README.md +++ b/README.md @@ -78,8 +78,8 @@ type Rss struct { ## Online -* Try online via WASM: [https://xml-to-go.github.io/](https://xml-to-go.github.io/), thanks [YaroslavPodorvanov](https://github.com/YaroslavPodorvanov)! -* ([offline as of 03/2022](http://web.archive.org/web/20230000000000*/https://onlinetool.io/xmltogo/)) -- try it online at [https://www.onlinetool.io/xmltogo/](https://www.onlinetool.io/xmltogo/) -- thanks, [kjk](https://github.com/kjk)! +* try online via WASM: [https://xml-to-go.github.io/](https://xml-to-go.github.io/), thanks [YaroslavPodorvanov](https://github.com/YaroslavPodorvanov)! +* try it online at [https://blog.kowalczyk.info/tools/xmltogo/](https://blog.kowalczyk.info/tools/xmltogo/) -- thanks, [kjk](https://github.com/kjk)! ## About From b26495f8511f7b7ac787bc7162f86a6c14ba608e Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Mon, 10 Apr 2023 11:51:16 +0200 Subject: [PATCH 13/28] v0.1.19 --- Makefile | 2 +- go.mod | 2 +- go.sum | 13 ++++++++++--- packaging/deb/control.amd64 | 2 +- packaging/deb/control.any | 2 +- packaging/deb/zek/DEBIAN/control | 2 +- packaging/rpm/zek.spec | 2 +- version.go | 2 +- 8 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 4791d09..04af68f 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ SHELL = /bin/bash TARGETS = zek PKGNAME = zek ARCH = amd64 -VERSION = 0.1.18 +VERSION = 0.1.19 .PHONY: all all: $(TARGETS) diff --git a/go.mod b/go.mod index 98e5648..b5896df 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,5 @@ go 1.12 require ( github.com/sethgrid/pester v1.2.0 - golang.org/x/net v0.7.0 + golang.org/x/net v0.9.0 ) diff --git a/go.sum b/go.sum index b3c256e..b0d621b 100644 --- a/go.sum +++ b/go.sum @@ -4,28 +4,35 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= +golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/packaging/deb/control.amd64 b/packaging/deb/control.amd64 index c38933b..64475e7 100644 --- a/packaging/deb/control.amd64 +++ b/packaging/deb/control.amd64 @@ -1,5 +1,5 @@ Package: zek -Version: 0.1.18 +Version: 0.1.19 Section: utils Priority: optional Architecture: amd64 diff --git a/packaging/deb/control.any b/packaging/deb/control.any index 3662082..7e406d8 100644 --- a/packaging/deb/control.any +++ b/packaging/deb/control.any @@ -1,5 +1,5 @@ Package: zek -Version: 0.1.18 +Version: 0.1.19 Section: utils Priority: optional Architecture: any diff --git a/packaging/deb/zek/DEBIAN/control b/packaging/deb/zek/DEBIAN/control index c38933b..64475e7 100644 --- a/packaging/deb/zek/DEBIAN/control +++ b/packaging/deb/zek/DEBIAN/control @@ -1,5 +1,5 @@ Package: zek -Version: 0.1.18 +Version: 0.1.19 Section: utils Priority: optional Architecture: amd64 diff --git a/packaging/rpm/zek.spec b/packaging/rpm/zek.spec index d4dcf3e..8c9700b 100644 --- a/packaging/rpm/zek.spec +++ b/packaging/rpm/zek.spec @@ -1,6 +1,6 @@ Summary: Generate a Go struct from an XML document. Name: zek -Version: 0.1.18 +Version: 0.1.19 Release: 0 License: GPL BuildArch: x86_64 diff --git a/version.go b/version.go index 3cb31db..f799822 100644 --- a/version.go +++ b/version.go @@ -22,4 +22,4 @@ package zek // Version of application. -const Version = "0.1.18" +const Version = "0.1.19" From f668fc00de181b71aac0d6d51bb22d1c48ebc7ee Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Mon, 10 Apr 2023 11:52:58 +0200 Subject: [PATCH 14/28] update makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 04af68f..a3ab2cf 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,7 @@ rpm: $(TARGETS) docs/$(PKGNAME).1 .PHONY: release release: - @export GITHUB_TOKEN="..." + @echo export GITHUB_TOKEN="..." @echo go tag $(VERSION) @echo goreleaser release --rm-dist From 3df0e2695741940e49a3bbe8c607b5341a9ceee1 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Wed, 2 Aug 2023 03:32:19 +0200 Subject: [PATCH 15/28] prepare readAtMost flag --- cmd/zek/main.go | 1 + node.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/zek/main.go b/cmd/zek/main.go index 90102fc..e1bb721 100644 --- a/cmd/zek/main.go +++ b/cmd/zek/main.go @@ -35,6 +35,7 @@ var ( outputFile = flag.String("o", "", "if set, write to output file, not stdout") packageName = flag.String("P", "", "if set, write out struct within a package with the given name") fixedBanner = flag.Bool("B", false, "use a fixed banner string (e.g. for CI)") + readAtMost = flag.Int("S", 1<<30, "read at most this many bytes, approximately") ) func main() { diff --git a/node.go b/node.go index ff0bf52..fbc8d0d 100644 --- a/node.go +++ b/node.go @@ -92,7 +92,7 @@ func readNode(r io.Reader, root *Node, maxExamples int) (node *Node, n int64, er return root, cw.n, nil } -// ReadFrom reads XML from a reader. +// ReadFrom reads XML from a reader. TODO: pass read options. func (node *Node) ReadFrom(r io.Reader) (int64, error) { nn, n, err := readNode(r, nil, node.MaxExamples) if err != nil { From 1b3333007064f065293c06c7400d394ce679b212 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Wed, 2 Aug 2023 10:23:15 +0200 Subject: [PATCH 16/28] feature: add flag to limit bytes read For large files, partial reads can suffice. The `-S N` flag allows to specify an number of bytes after which the processing is stopped and the struct built up so far is emitted. --- README.md | 2 ++ cmd/zek/main.go | 8 ++++++-- docs/zek.md | 3 +++ go.mod | 2 +- go.sum | 15 ++++++++++----- node.go | 18 ++++++++++++++---- node_test.go | 8 ++++---- structwriter_test.go | 2 +- 8 files changed, 41 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index b894e47..b0b646c 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,8 @@ Usage of zek: -F skip formatting -P string if set, write out struct within a package with the given name + -S int + read at most this many bytes, approximately (0=unlimited) -c emit more compact struct (noop, as this is the default since 0.1.7) -d debug output -e add comments with example diff --git a/cmd/zek/main.go b/cmd/zek/main.go index e1bb721..f764590 100644 --- a/cmd/zek/main.go +++ b/cmd/zek/main.go @@ -35,7 +35,7 @@ var ( outputFile = flag.String("o", "", "if set, write to output file, not stdout") packageName = flag.String("P", "", "if set, write out struct within a package with the given name") fixedBanner = flag.Bool("B", false, "use a fixed banner string (e.g. for CI)") - readAtMost = flag.Int("S", 1<<30, "read at most this many bytes, approximately") + readAtMost = flag.Int64("S", 0, "read at most this many bytes, approximately (0=unlimited)") ) func main() { @@ -74,7 +74,11 @@ func main() { } reader = io.MultiReader(rs...) } - if _, err := root.ReadFrom(reader); err != nil { + opts := zek.ReadOpts{ + MaxExamples: *maxExamples, + ReadAtMost: *readAtMost, + } + if _, err := root.ReadFrom(reader, &opts); err != nil { log.Fatal(err) } // Move root, if we have a tagName. Ignore unknown names. diff --git a/docs/zek.md b/docs/zek.md index 1d81fe5..a088b0f 100644 --- a/docs/zek.md +++ b/docs/zek.md @@ -75,6 +75,9 @@ at https://www.onlinetool.io/xmltogo/. -s : Strict parsing. +-S +: raed at most this many bytes, approximately (0=unlimited) + -t : Emit struct for tag matching this name. diff --git a/go.mod b/go.mod index b5896df..c868deb 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,5 @@ go 1.12 require ( github.com/sethgrid/pester v1.2.0 - golang.org/x/net v0.9.0 + golang.org/x/net v0.13.0 ) diff --git a/go.sum b/go.sum index b0d621b..dfaa7fb 100644 --- a/go.sum +++ b/go.sum @@ -3,14 +3,16 @@ github.com/sethgrid/pester v1.2.0/go.mod h1:hEUINb4RqvDxtoCaU0BNT/HV4ig5kfgOasrf github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= -golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.13.0 h1:Nvo8UFsZ8X3BhAC9699Z1j7XQ3rsZnUUm7jfBEk1ueY= +golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -20,17 +22,20 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= +golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/node.go b/node.go index fbc8d0d..7cb390c 100644 --- a/node.go +++ b/node.go @@ -45,10 +45,16 @@ type Node struct { childFreqs map[xml.Name]int // Count child tag occurrences, used temporarily. } +// ReadOpts groups options for parsing. +type ReadOpts struct { + MaxExamples int + ReadAtMost int64 +} + // readNode reads XML from a reader and returns a parsed node. If node is // given, it is reused, allowing for multiple passes (e.g. from multiple // files). XXX: maxExamples should be factored out into options. -func readNode(r io.Reader, root *Node, maxExamples int) (node *Node, n int64, err error) { +func readNode(r io.Reader, root *Node, opts *ReadOpts) (node *Node, n int64, err error) { var ( cw = countwriter{} dec = xml.NewDecoder(io.TeeReader(r, &cw)) @@ -60,6 +66,7 @@ func readNode(r io.Reader, root *Node, maxExamples int) (node *Node, n int64, er } stack := Stack{} stack.Put(root) +OUTER: for { token, err := dec.Token() if err == io.EOF { @@ -76,13 +83,16 @@ func readNode(r io.Reader, root *Node, maxExamples int) (node *Node, n int64, er case xml.EndElement: n := stack.Pop().(*Node) n.End() + if opts.ReadAtMost > 0 && cw.n > opts.ReadAtMost { + break OUTER + } case xml.CharData: v := strings.TrimSpace(string(t)) if v == "" { break } n := stack.Peek().(*Node) - if len(n.Examples) < maxExamples { + if len(n.Examples) < opts.MaxExamples { // XXX: sample better, e.g. reservoir dictionary. n.Examples = append(n.Examples, v) } @@ -93,8 +103,8 @@ func readNode(r io.Reader, root *Node, maxExamples int) (node *Node, n int64, er } // ReadFrom reads XML from a reader. TODO: pass read options. -func (node *Node) ReadFrom(r io.Reader) (int64, error) { - nn, n, err := readNode(r, nil, node.MaxExamples) +func (node *Node) ReadFrom(r io.Reader, opts *ReadOpts) (int64, error) { + nn, n, err := readNode(r, nil, opts) if err != nil { return n, err } diff --git a/node_test.go b/node_test.go index f409df8..f4eeac3 100644 --- a/node_test.go +++ b/node_test.go @@ -419,7 +419,7 @@ func TestNodeReadFrom(t *testing.T) { for _, c := range cases { r := strings.NewReader(c.input) node := new(Node) - _, err := node.ReadFrom(r) + _, err := node.ReadFrom(r, &ReadOpts{MaxExamples: 10}) if err != c.err { t.Errorf("got %v, want %v", err, c.err) } @@ -462,7 +462,7 @@ func TestHeight(t *testing.T) { for _, c := range cases { r := strings.NewReader(c.input) node := new(Node) - _, err := node.ReadFrom(r) + _, err := node.ReadFrom(r, &ReadOpts{MaxExamples: 10}) if err != nil { t.Errorf("failed to parse tree: %s", err) } @@ -475,7 +475,7 @@ func TestHeight(t *testing.T) { func TestByName(t *testing.T) { r := strings.NewReader(``) root := new(Node) - if _, err := root.ReadFrom(r); err != nil { + if _, err := root.ReadFrom(r, &ReadOpts{MaxExamples: 10}); err != nil { t.Errorf("got %v, want nil", err) } @@ -892,7 +892,7 @@ func TestNodeReadFromAll(t *testing.T) { } node := new(Node) - _, err := node.ReadFrom(io.MultiReader(readers...)) + _, err := node.ReadFrom(io.MultiReader(readers...), &ReadOpts{MaxExamples: 10}) if err != c.err { t.Errorf("got %v, want %v", err, c.err) } diff --git a/structwriter_test.go b/structwriter_test.go index 2eec9b5..c4b9c2c 100644 --- a/structwriter_test.go +++ b/structwriter_test.go @@ -178,7 +178,7 @@ func TestWriteNode(t *testing.T) { node := new(Node) node.MaxExamples = 10 - if _, err := node.ReadFrom(f); err != nil { + if _, err := node.ReadFrom(f, &ReadOpts{MaxExamples: 10}); err != nil { t.Errorf("failed to read XML input: %s", err) } From 6fc5f17c494e363744c870214f25d4526d45c1aa Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Wed, 2 Aug 2023 10:25:22 +0200 Subject: [PATCH 17/28] v0.1.20 --- Makefile | 2 +- packaging/deb/control.amd64 | 2 +- packaging/deb/control.any | 2 +- packaging/deb/zek/DEBIAN/control | 2 +- packaging/rpm/zek.spec | 2 +- version.go | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index a3ab2cf..15f2d34 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ SHELL = /bin/bash TARGETS = zek PKGNAME = zek ARCH = amd64 -VERSION = 0.1.19 +VERSION = 0.1.20 .PHONY: all all: $(TARGETS) diff --git a/packaging/deb/control.amd64 b/packaging/deb/control.amd64 index 64475e7..72409fe 100644 --- a/packaging/deb/control.amd64 +++ b/packaging/deb/control.amd64 @@ -1,5 +1,5 @@ Package: zek -Version: 0.1.19 +Version: 0.1.20 Section: utils Priority: optional Architecture: amd64 diff --git a/packaging/deb/control.any b/packaging/deb/control.any index 7e406d8..f09db58 100644 --- a/packaging/deb/control.any +++ b/packaging/deb/control.any @@ -1,5 +1,5 @@ Package: zek -Version: 0.1.19 +Version: 0.1.20 Section: utils Priority: optional Architecture: any diff --git a/packaging/deb/zek/DEBIAN/control b/packaging/deb/zek/DEBIAN/control index 64475e7..72409fe 100644 --- a/packaging/deb/zek/DEBIAN/control +++ b/packaging/deb/zek/DEBIAN/control @@ -1,5 +1,5 @@ Package: zek -Version: 0.1.19 +Version: 0.1.20 Section: utils Priority: optional Architecture: amd64 diff --git a/packaging/rpm/zek.spec b/packaging/rpm/zek.spec index 8c9700b..38e29e7 100644 --- a/packaging/rpm/zek.spec +++ b/packaging/rpm/zek.spec @@ -1,6 +1,6 @@ Summary: Generate a Go struct from an XML document. Name: zek -Version: 0.1.19 +Version: 0.1.20 Release: 0 License: GPL BuildArch: x86_64 diff --git a/version.go b/version.go index f799822..821da72 100644 --- a/version.go +++ b/version.go @@ -22,4 +22,4 @@ package zek // Version of application. -const Version = "0.1.19" +const Version = "0.1.20" From b5730ec918e0ce593401e0fdc2fbcf4341443e62 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Wed, 2 Aug 2023 10:39:58 +0200 Subject: [PATCH 18/28] fix: switch from max bytes read to max tokens read --- README.md | 2 +- cmd/zek/main.go | 4 ++-- docs/zek.md | 2 +- node.go | 6 ++++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b0b646c..3e71cb1 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ Usage of zek: -P string if set, write out struct within a package with the given name -S int - read at most this many bytes, approximately (0=unlimited) + read at most this many tags, approximately (0=unlimited) -c emit more compact struct (noop, as this is the default since 0.1.7) -d debug output -e add comments with example diff --git a/cmd/zek/main.go b/cmd/zek/main.go index f764590..f29f84b 100644 --- a/cmd/zek/main.go +++ b/cmd/zek/main.go @@ -35,7 +35,7 @@ var ( outputFile = flag.String("o", "", "if set, write to output file, not stdout") packageName = flag.String("P", "", "if set, write out struct within a package with the given name") fixedBanner = flag.Bool("B", false, "use a fixed banner string (e.g. for CI)") - readAtMost = flag.Int64("S", 0, "read at most this many bytes, approximately (0=unlimited)") + readAtMost = flag.Int64("S", 0, "read at most this many tags, approximately (0=unlimited)") ) func main() { @@ -76,7 +76,7 @@ func main() { } opts := zek.ReadOpts{ MaxExamples: *maxExamples, - ReadAtMost: *readAtMost, + MaxTokens: *readAtMost, } if _, err := root.ReadFrom(reader, &opts); err != nil { log.Fatal(err) diff --git a/docs/zek.md b/docs/zek.md index a088b0f..8299e89 100644 --- a/docs/zek.md +++ b/docs/zek.md @@ -76,7 +76,7 @@ at https://www.onlinetool.io/xmltogo/. : Strict parsing. -S -: raed at most this many bytes, approximately (0=unlimited) +: raed at most this many tokens, approximately (0=unlimited) -t : Emit struct for tag matching this name. diff --git a/node.go b/node.go index 7cb390c..305639d 100644 --- a/node.go +++ b/node.go @@ -48,7 +48,7 @@ type Node struct { // ReadOpts groups options for parsing. type ReadOpts struct { MaxExamples int - ReadAtMost int64 + MaxTokens int64 } // readNode reads XML from a reader and returns a parsed node. If node is @@ -66,6 +66,7 @@ func readNode(r io.Reader, root *Node, opts *ReadOpts) (node *Node, n int64, err } stack := Stack{} stack.Put(root) + var i int64 OUTER: for { token, err := dec.Token() @@ -75,6 +76,7 @@ OUTER: if err != nil { return root, cw.n, err } + i++ switch t := token.(type) { case xml.StartElement: parent := stack.Peek().(*Node) @@ -83,7 +85,7 @@ OUTER: case xml.EndElement: n := stack.Pop().(*Node) n.End() - if opts.ReadAtMost > 0 && cw.n > opts.ReadAtMost { + if opts.MaxTokens > 0 && i > opts.MaxTokens { break OUTER } case xml.CharData: From a6e1ccfc531d41292af1510aeb3226b673058ec6 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Wed, 2 Aug 2023 10:40:11 +0200 Subject: [PATCH 19/28] v0.1.21 --- Makefile | 2 +- packaging/deb/control.amd64 | 2 +- packaging/deb/control.any | 2 +- packaging/deb/zek/DEBIAN/control | 2 +- packaging/rpm/zek.spec | 2 +- version.go | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 15f2d34..9cc3a15 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ SHELL = /bin/bash TARGETS = zek PKGNAME = zek ARCH = amd64 -VERSION = 0.1.20 +VERSION = 0.1.21 .PHONY: all all: $(TARGETS) diff --git a/packaging/deb/control.amd64 b/packaging/deb/control.amd64 index 72409fe..d1ee457 100644 --- a/packaging/deb/control.amd64 +++ b/packaging/deb/control.amd64 @@ -1,5 +1,5 @@ Package: zek -Version: 0.1.20 +Version: 0.1.21 Section: utils Priority: optional Architecture: amd64 diff --git a/packaging/deb/control.any b/packaging/deb/control.any index f09db58..71e5712 100644 --- a/packaging/deb/control.any +++ b/packaging/deb/control.any @@ -1,5 +1,5 @@ Package: zek -Version: 0.1.20 +Version: 0.1.21 Section: utils Priority: optional Architecture: any diff --git a/packaging/deb/zek/DEBIAN/control b/packaging/deb/zek/DEBIAN/control index 72409fe..d1ee457 100644 --- a/packaging/deb/zek/DEBIAN/control +++ b/packaging/deb/zek/DEBIAN/control @@ -1,5 +1,5 @@ Package: zek -Version: 0.1.20 +Version: 0.1.21 Section: utils Priority: optional Architecture: amd64 diff --git a/packaging/rpm/zek.spec b/packaging/rpm/zek.spec index 38e29e7..e469b57 100644 --- a/packaging/rpm/zek.spec +++ b/packaging/rpm/zek.spec @@ -1,6 +1,6 @@ Summary: Generate a Go struct from an XML document. Name: zek -Version: 0.1.20 +Version: 0.1.21 Release: 0 License: GPL BuildArch: x86_64 diff --git a/version.go b/version.go index 821da72..ed29d55 100644 --- a/version.go +++ b/version.go @@ -22,4 +22,4 @@ package zek // Version of application. -const Version = "0.1.20" +const Version = "0.1.21" From e073a770ffec7372cc9fa166e6671a70ce02e041 Mon Sep 17 00:00:00 2001 From: Yaroslav Podorvanov Date: Tue, 2 Jan 2024 22:14:22 +0200 Subject: [PATCH 20/28] just run tests --- .github/workflows/code_quality.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/code_quality.yml diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml new file mode 100644 index 0000000..a25da18 --- /dev/null +++ b/.github/workflows/code_quality.yml @@ -0,0 +1,22 @@ +name: Code quality + +on: + push: + branches: + - main + +jobs: + code-quality: + name: Code quality + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@master + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.12' + + - name: Unit tests + run: go test -v ./... From ea18cab922bb76875b54218beb955d35b3bcaf54 Mon Sep 17 00:00:00 2001 From: Yaroslav Podorvanov Date: Tue, 2 Jan 2024 22:17:43 +0200 Subject: [PATCH 21/28] change branch name for actions --- .github/workflows/code_quality.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml index a25da18..ff0a205 100644 --- a/.github/workflows/code_quality.yml +++ b/.github/workflows/code_quality.yml @@ -3,7 +3,7 @@ name: Code quality on: push: branches: - - main + - master jobs: code-quality: From 5a5c703afa96c91eb2267443a3155d83fcaadc2a Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Tue, 2 Jan 2024 21:23:53 +0100 Subject: [PATCH 22/28] go.mod: update required version --- .github/workflows/code_quality.yml | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml index ff0a205..bc0c197 100644 --- a/.github/workflows/code_quality.yml +++ b/.github/workflows/code_quality.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: '1.12' + go-version: '1.14' - name: Unit tests run: go test -v ./... diff --git a/go.mod b/go.mod index c868deb..cfeda73 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/miku/zek -go 1.12 +go 1.14 require ( github.com/sethgrid/pester v1.2.0 From c560c102edce0e2209abff3daea8029d85e34fb7 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Tue, 2 Jan 2024 21:27:11 +0100 Subject: [PATCH 23/28] go.mod: minimal go version is 1.16 although sethgrid/pester asserts 1.14 it uses io.NopCloser which was only added (moved) in 1.16 (https://pkg.go.dev/io#NopCloser) --- .github/workflows/code_quality.yml | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml index bc0c197..7c4b8c6 100644 --- a/.github/workflows/code_quality.yml +++ b/.github/workflows/code_quality.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: '1.14' + go-version: '1.16' - name: Unit tests run: go test -v ./... diff --git a/go.mod b/go.mod index cfeda73..0ba6617 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/miku/zek -go 1.14 +go 1.16 require ( github.com/sethgrid/pester v1.2.0 From 202e712b64684580e429f3dca1dc045133392ccc Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Tue, 2 Jan 2024 23:40:25 +0100 Subject: [PATCH 24/28] update deps --- go.mod | 2 +- go.sum | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 0ba6617..27bdaee 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,5 @@ go 1.16 require ( github.com/sethgrid/pester v1.2.0 - golang.org/x/net v0.13.0 + golang.org/x/net v0.19.0 ) diff --git a/go.sum b/go.sum index dfaa7fb..7069ebf 100644 --- a/go.sum +++ b/go.sum @@ -3,7 +3,7 @@ github.com/sethgrid/pester v1.2.0/go.mod h1:hEUINb4RqvDxtoCaU0BNT/HV4ig5kfgOasrf github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= +golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -11,8 +11,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.13.0 h1:Nvo8UFsZ8X3BhAC9699Z1j7XQ3rsZnUUm7jfBEk1ueY= -golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= +golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= +golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -23,19 +23,19 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= +golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= -golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= From a1ad2e1c0b54f4853561ce53a671224bde9a95ef Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Wed, 3 Jan 2024 10:30:53 +0100 Subject: [PATCH 25/28] use go 1.17 (build tags) --- .github/workflows/code_quality.yml | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml index 7c4b8c6..85b7024 100644 --- a/.github/workflows/code_quality.yml +++ b/.github/workflows/code_quality.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: '1.16' + go-version: '1.17' - name: Unit tests run: go test -v ./... diff --git a/go.mod b/go.mod index 27bdaee..3239a40 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/miku/zek -go 1.16 +go 1.17 require ( github.com/sethgrid/pester v1.2.0 From 5d3a4323c921338c23eca05ddc6c6b2baf31c943 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Wed, 3 Jan 2024 10:34:00 +0100 Subject: [PATCH 26/28] fix go.mod --- go.mod | 2 ++ 1 file changed, 2 insertions(+) diff --git a/go.mod b/go.mod index 3239a40..52a29b7 100644 --- a/go.mod +++ b/go.mod @@ -6,3 +6,5 @@ require ( github.com/sethgrid/pester v1.2.0 golang.org/x/net v0.19.0 ) + +require golang.org/x/text v0.14.0 // indirect From 33863768e6c2de0d5db3c0f566fbd7e9216c070d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?p=C3=A9riode?= Date: Fri, 27 May 2022 01:02:24 +0200 Subject: [PATCH 27/28] added named struct extraction flag --- cmd/zek/main.go | 2 ++ structwriter.go | 93 +++++++++++++++++++++++++++++-------------------- 2 files changed, 57 insertions(+), 38 deletions(-) diff --git a/cmd/zek/main.go b/cmd/zek/main.go index f29f84b..751e9d7 100644 --- a/cmd/zek/main.go +++ b/cmd/zek/main.go @@ -23,6 +23,7 @@ var ( debug = flag.Bool("d", false, "debug output") createExampleProgram = flag.Bool("p", false, "write out an example program") tagName = flag.String("t", "", "emit struct for tag matching this name") + replaceStructs = flag.String("r", "", "replace anonymous structs by tags matching this name, e.g. 'name1 name2'") skipFormatting = flag.Bool("F", false, "skip formatting") strict = flag.Bool("s", false, "strict parsing and writing") exampleMaxChars = flag.Int("x", 25, "max chars for example") @@ -104,6 +105,7 @@ func main() { sw.Strict = *strict sw.ExampleMaxChars = *exampleMaxChars sw.Compact = !*nonCompact + sw.ReplaceStruct = strings.Split(*replaceStructs, " ") sw.UniqueExamples = *uniqueExamples sw.OmitEmptyText = *omitEmptyText if *fixedBanner { diff --git a/structwriter.go b/structwriter.go index ece6f37..0f5c1ba 100644 --- a/structwriter.go +++ b/structwriter.go @@ -100,6 +100,7 @@ type StructWriter struct { Strict bool // Whether to ignore implementation holes. WithJSONTags bool // Include JSON struct tags. Compact bool // Emit more compact struct. + ReplaceStruct []string // Replaces anonymous struct for into a named struct of the same name UniqueExamples bool // Filter out duplicated examples OmitEmptyText bool // Don't generate Text fields if no example elements have chardata. } @@ -242,53 +243,69 @@ func (sw *StructWriter) writeNode(node *Node, top bool) (err error) { fmt.Fprintf(sew, "%s\n", s) return err } - io.WriteString(sew, "struct {\n") - if top { - sw.writeNameField(sew, node) - } - if !sw.OmitEmptyText || len(node.Examples) > 0 { - sw.writeChardataField(sew, node) + + var namedStruct string + + if !top { + for _, s := range sw.ReplaceStruct { + if s == sw.NameFunc(node.Name.Local) { + namedStruct = s + } + } } - // Helper to check for name clash of attribute with any generated field name. - isValidName := func(name string) bool { - if name == sw.TextFieldNames[0] { - return false + + if namedStruct == "" { + io.WriteString(sew, "struct {\n") + if top { + sw.writeNameField(sew, node) } - for _, child := range node.Children { - if name == sw.NameFunc(child.Name.Local) { + if !sw.OmitEmptyText || len(node.Examples) > 0 { + sw.writeChardataField(sew, node) + } + // Helper to check for name clash of attribute with any generated field name. + isValidName := func(name string) bool { + if name == sw.TextFieldNames[0] { return false } - } - return true - } - // Write attributes. XXX: Better handling of duplicate attributes. - written := make(map[string]bool) - for _, attr := range node.Attr { - name := sw.NameFunc(attr.Name.Local) - for _, prefix := range sw.AttributePrefixes { - if isValidName(name) { - break + for _, child := range node.Children { + if name == sw.NameFunc(child.Name.Local) { + return false + } } - name = fmt.Sprintf("%s%s", prefix, name) - } - if !isValidName(name) { - return fmt.Errorf("name clash: %s", attr.Name.Local) + return true } - if _, ok := written[attr.Name.Local]; ok { - if sw.Strict { - log.Fatalf("[not implemented] duplicate local attribute name: %s", attr) - } else { - log.Printf("warning: duplicate local attribute name: %s", attr) + // Write attributes. XXX: Better handling of duplicate attributes. + written := make(map[string]bool) + for _, attr := range node.Attr { + name := sw.NameFunc(attr.Name.Local) + for _, prefix := range sw.AttributePrefixes { + if isValidName(name) { + break + } + name = fmt.Sprintf("%s%s", prefix, name) + } + if !isValidName(name) { + return fmt.Errorf("name clash: %s", attr.Name.Local) } - continue + if _, ok := written[attr.Name.Local]; ok { + if sw.Strict { + log.Fatalf("[not implemented] duplicate local attribute name: %s", attr) + } else { + log.Printf("warning: duplicate local attribute name: %s", attr) + } + continue + } + sw.writeAttrField(sew, name, "string", attr) + written[attr.Name.Local] = true } - sw.writeAttrField(sew, name, "string", attr) - written[attr.Name.Local] = true - } - for _, child := range node.Children { - sw.writeNode(child, false) + for _, child := range node.Children { + sw.writeNode(child, false) + } + io.WriteString(sew, "} ") + } else { + io.WriteString(sew, namedStruct+" ") } - io.WriteString(sew, "} ") + if !top { sw.writeStructTag(sew, node) } From f911d47ea31903494964aeaa2cd2ef4136457edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?p=C3=A9riode?= Date: Sun, 21 Jan 2024 14:21:01 +0100 Subject: [PATCH 28/28] feature: flag to not inline the structs --- cmd/zek/main.go | 4 +- structwriter.go | 18 ++------ structwriter_test.go | 103 ++++++++++++++++++++++++++----------------- testdata/w.16.go | 10 +++++ testdata/w.16.xml | 9 ++++ 5 files changed, 88 insertions(+), 56 deletions(-) create mode 100644 testdata/w.16.go create mode 100644 testdata/w.16.xml diff --git a/cmd/zek/main.go b/cmd/zek/main.go index 751e9d7..9c4a8ae 100644 --- a/cmd/zek/main.go +++ b/cmd/zek/main.go @@ -23,7 +23,7 @@ var ( debug = flag.Bool("d", false, "debug output") createExampleProgram = flag.Bool("p", false, "write out an example program") tagName = flag.String("t", "", "emit struct for tag matching this name") - replaceStructs = flag.String("r", "", "replace anonymous structs by tags matching this name, e.g. 'name1 name2'") + notInlineStructs = flag.Bool("I", false, "do not inline children tags as anonymous structs") skipFormatting = flag.Bool("F", false, "skip formatting") strict = flag.Bool("s", false, "strict parsing and writing") exampleMaxChars = flag.Int("x", 25, "max chars for example") @@ -105,7 +105,7 @@ func main() { sw.Strict = *strict sw.ExampleMaxChars = *exampleMaxChars sw.Compact = !*nonCompact - sw.ReplaceStruct = strings.Split(*replaceStructs, " ") + sw.InlineStructs = !*notInlineStructs sw.UniqueExamples = *uniqueExamples sw.OmitEmptyText = *omitEmptyText if *fixedBanner { diff --git a/structwriter.go b/structwriter.go index 0f5c1ba..17840e0 100644 --- a/structwriter.go +++ b/structwriter.go @@ -100,8 +100,8 @@ type StructWriter struct { Strict bool // Whether to ignore implementation holes. WithJSONTags bool // Include JSON struct tags. Compact bool // Emit more compact struct. - ReplaceStruct []string // Replaces anonymous struct for into a named struct of the same name - UniqueExamples bool // Filter out duplicated examples + InlineStructs bool // Inlines children tags as anonymous structs. + UniqueExamples bool // Filter out duplicated examples. OmitEmptyText bool // Don't generate Text fields if no example elements have chardata. } @@ -244,17 +244,7 @@ func (sw *StructWriter) writeNode(node *Node, top bool) (err error) { return err } - var namedStruct string - - if !top { - for _, s := range sw.ReplaceStruct { - if s == sw.NameFunc(node.Name.Local) { - namedStruct = s - } - } - } - - if namedStruct == "" { + if sw.InlineStructs || top { io.WriteString(sew, "struct {\n") if top { sw.writeNameField(sew, node) @@ -303,7 +293,7 @@ func (sw *StructWriter) writeNode(node *Node, top bool) (err error) { } io.WriteString(sew, "} ") } else { - io.WriteString(sew, namedStruct+" ") + io.WriteString(sew, sw.NameFunc(node.Name.Local)+" ") } if !top { diff --git a/structwriter_test.go b/structwriter_test.go index c4b9c2c..8bbeab8 100644 --- a/structwriter_test.go +++ b/structwriter_test.go @@ -78,72 +78,85 @@ func TestWriteNode(t *testing.T) { withComments bool omitEmptyText bool uniqueExamples bool + inlineStructs bool err error }{ { - input: "testdata/w.1.xml", - result: "testdata/w.1.go", - err: nil, + input: "testdata/w.1.xml", + result: "testdata/w.1.go", + inlineStructs: true, + err: nil, }, { - input: "testdata/w.2.xml", - result: "testdata/w.2.go", - err: nil, + input: "testdata/w.2.xml", + result: "testdata/w.2.go", + inlineStructs: true, + err: nil, }, { - input: "testdata/w.3.xml", - result: "testdata/w.3.go", - err: nil, + input: "testdata/w.3.xml", + result: "testdata/w.3.go", + inlineStructs: true, + err: nil, }, { - input: "testdata/w.4.xml", - result: "testdata/w.4.go", - err: nil, + input: "testdata/w.4.xml", + result: "testdata/w.4.go", + inlineStructs: true, + err: nil, }, { - input: "testdata/w.5.xml", - result: "testdata/w.5.go", - err: nil, + input: "testdata/w.5.xml", + result: "testdata/w.5.go", + inlineStructs: true, + err: nil, }, { - input: "testdata/w.6.xml", - result: "testdata/w.6.go", - err: nil, + input: "testdata/w.6.xml", + result: "testdata/w.6.go", + inlineStructs: true, + err: nil, }, { - input: "testdata/w.7.xml", - result: "testdata/w.7.go", - err: nil, + input: "testdata/w.7.xml", + result: "testdata/w.7.go", + inlineStructs: true, + err: nil, }, { - input: "testdata/w.8.xml", - result: "testdata/w.8.go", - withComments: true, - err: nil, + input: "testdata/w.8.xml", + result: "testdata/w.8.go", + withComments: true, + inlineStructs: true, + err: nil, }, { - input: "testdata/w.9.xml", - result: "testdata/w.9.go", - withComments: true, - err: nil, + input: "testdata/w.9.xml", + result: "testdata/w.9.go", + withComments: true, + inlineStructs: true, + err: nil, }, { - input: "testdata/w.10.xml", - result: "testdata/w.10.go", - withComments: true, - err: nil, + input: "testdata/w.10.xml", + result: "testdata/w.10.go", + withComments: true, + inlineStructs: true, + err: nil, }, { - input: "testdata/w.11.xml", - result: "testdata/w.11.go", - withComments: true, - err: nil, + input: "testdata/w.11.xml", + result: "testdata/w.11.go", + withComments: true, + inlineStructs: true, + err: nil, }, { input: "testdata/w.12.xml", result: "testdata/w.12.go", withComments: true, uniqueExamples: false, + inlineStructs: true, err: nil, }, { @@ -151,6 +164,7 @@ func TestWriteNode(t *testing.T) { result: "testdata/w.13.go", withComments: true, uniqueExamples: true, + inlineStructs: true, err: nil, }, { @@ -158,13 +172,21 @@ func TestWriteNode(t *testing.T) { result: "testdata/w.14.go", withComments: true, uniqueExamples: true, + inlineStructs: true, omitEmptyText: true, err: nil, }, { - input: "testdata/w.15.xml", - result: "testdata/w.15.go", - err: nil, + input: "testdata/w.15.xml", + result: "testdata/w.15.go", + inlineStructs: true, + err: nil, + }, + { + input: "testdata/w.16.xml", + result: "testdata/w.16.go", + inlineStructs: false, + err: nil, }, } @@ -187,6 +209,7 @@ func TestWriteNode(t *testing.T) { sw.WithComments = c.withComments sw.UniqueExamples = c.uniqueExamples sw.OmitEmptyText = c.omitEmptyText + sw.InlineStructs = c.inlineStructs if err := sw.WriteNode(node); err != c.err { t.Errorf("WriteNode failed: got %v, want %v", err, c.err) diff --git a/testdata/w.16.go b/testdata/w.16.go new file mode 100644 index 0000000..8d8aeb7 --- /dev/null +++ b/testdata/w.16.go @@ -0,0 +1,10 @@ +package main + +import "encoding/xml" + +type A struct { + XMLName xml.Name `xml:"a"` + Text string `xml:",chardata"` + B B `xml:"b"` + A A `xml:"a"` +} diff --git a/testdata/w.16.xml b/testdata/w.16.xml new file mode 100644 index 0000000..37fad67 --- /dev/null +++ b/testdata/w.16.xml @@ -0,0 +1,9 @@ + + Europe + + Germany + + Leipzig + + +