From 734c2dd4bb8f87461b4461f85c2d8b073c4ce3d9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Jun 2022 21:39:27 +0000 Subject: [PATCH 01/33] build(deps): bump github.com/stretchr/testify from 1.7.1 to 1.7.2 Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.1 to 1.7.2. - [Release notes](https://github.com/stretchr/testify/releases) - [Commits](https://github.com/stretchr/testify/compare/v1.7.1...v1.7.2) --- updated-dependencies: - dependency-name: github.com/stretchr/testify dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index fb8cb0f..fb8ea28 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/json-iterator/go v1.1.12 github.com/mitchellh/mapstructure v1.5.0 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/stretchr/testify v1.7.1 + github.com/stretchr/testify v1.7.2 github.com/yosuke-furukawa/json5 v0.1.1 golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index be8441a..29b676e 100644 --- a/go.sum +++ b/go.sum @@ -63,8 +63,9 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= +github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= From ea79da951eec97bfca89ce6fd712cc28c3da6b7c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Jun 2022 21:52:06 +0000 Subject: [PATCH 02/33] build(deps): bump github.com/gookit/goutil from 0.5.2 to 0.5.4 Bumps [github.com/gookit/goutil](https://github.com/gookit/goutil) from 0.5.2 to 0.5.4. - [Release notes](https://github.com/gookit/goutil/releases) - [Commits](https://github.com/gookit/goutil/compare/v0.5.2...v0.5.4) --- updated-dependencies: - dependency-name: github.com/gookit/goutil dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index fb8ea28..606040a 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( github.com/BurntSushi/toml v1.1.0 - github.com/gookit/goutil v0.5.2 + github.com/gookit/goutil v0.5.4 github.com/gookit/ini/v2 v2.1.0 github.com/hashicorp/hcl v1.0.0 github.com/hashicorp/hcl/v2 v2.12.0 diff --git a/go.sum b/go.sum index 29b676e..40e615f 100644 --- a/go.sum +++ b/go.sum @@ -18,11 +18,12 @@ github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaW github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/gookit/color v1.5.0 h1:1Opow3+BWDwqor78DcJkJCIwnkviFi+rrOANki9BUFw= github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo= +github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ= +github.com/gookit/color v1.5.1/go.mod h1:wZFzea4X8qN6vHOSP2apMb4/+w/orMznEzYsIHPaqKM= github.com/gookit/goutil v0.5.0/go.mod h1:pq1eTibwb2wN96jrci0xy7xogWzzo9CihOQJEAvz4yQ= -github.com/gookit/goutil v0.5.2 h1:1IbfIUiRV+Y+5IdgBeb/O7hWvq8OnnP1+sB/Ua2Q6jE= -github.com/gookit/goutil v0.5.2/go.mod h1:pq1eTibwb2wN96jrci0xy7xogWzzo9CihOQJEAvz4yQ= +github.com/gookit/goutil v0.5.4 h1:SUorRYjdeNyAP0f4w0VDh4J6N3V72j0Iium6fP+xhb4= +github.com/gookit/goutil v0.5.4/go.mod h1:NQJY4PEwCCW27s4bIxjEJQbsPnsxVhQqRF2xU6L3Qrk= github.com/gookit/ini/v2 v2.1.0 h1:L1qn8CfP1KYlbogKuMsJ3FiDdKDwvABCKeeuMWDlQzQ= github.com/gookit/ini/v2 v2.1.0/go.mod h1:r06awbwBtIHxjA7ndqWJkRgCAvSG+5FdSGrrbGfigtY= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= @@ -42,7 +43,6 @@ github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3v github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM= github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= @@ -80,6 +80,8 @@ github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRK golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g= +golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= @@ -89,11 +91,14 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE= +golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= From 4561cd92895b7c3d6dd9fad23c738af94f4f8aa0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Jun 2022 22:07:21 +0000 Subject: [PATCH 03/33] build(deps): bump github.com/gookit/ini/v2 from 2.1.0 to 2.1.1 Bumps [github.com/gookit/ini/v2](https://github.com/gookit/ini) from 2.1.0 to 2.1.1. - [Release notes](https://github.com/gookit/ini/releases) - [Commits](https://github.com/gookit/ini/compare/v2.1.0...v2.1.1) --- updated-dependencies: - dependency-name: github.com/gookit/ini/v2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 606040a..b47d6d5 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.15 require ( github.com/BurntSushi/toml v1.1.0 github.com/gookit/goutil v0.5.4 - github.com/gookit/ini/v2 v2.1.0 + github.com/gookit/ini/v2 v2.1.1 github.com/hashicorp/hcl v1.0.0 github.com/hashicorp/hcl/v2 v2.12.0 github.com/imdario/mergo v0.3.13 diff --git a/go.sum b/go.sum index 40e615f..8f0890b 100644 --- a/go.sum +++ b/go.sum @@ -21,11 +21,11 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/ github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo= github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ= github.com/gookit/color v1.5.1/go.mod h1:wZFzea4X8qN6vHOSP2apMb4/+w/orMznEzYsIHPaqKM= -github.com/gookit/goutil v0.5.0/go.mod h1:pq1eTibwb2wN96jrci0xy7xogWzzo9CihOQJEAvz4yQ= +github.com/gookit/goutil v0.5.3/go.mod h1:W0rVeVN9EcoRV+ODq91TXvqoUA87BXGi36WFVykCKRI= github.com/gookit/goutil v0.5.4 h1:SUorRYjdeNyAP0f4w0VDh4J6N3V72j0Iium6fP+xhb4= github.com/gookit/goutil v0.5.4/go.mod h1:NQJY4PEwCCW27s4bIxjEJQbsPnsxVhQqRF2xU6L3Qrk= -github.com/gookit/ini/v2 v2.1.0 h1:L1qn8CfP1KYlbogKuMsJ3FiDdKDwvABCKeeuMWDlQzQ= -github.com/gookit/ini/v2 v2.1.0/go.mod h1:r06awbwBtIHxjA7ndqWJkRgCAvSG+5FdSGrrbGfigtY= +github.com/gookit/ini/v2 v2.1.1 h1:q2VtSSl/ivTOZMPvxhjWxO3f146NvWM84jBQZETj/1o= +github.com/gookit/ini/v2 v2.1.1/go.mod h1:zkMTCrnE2QgDW0izB/pRtgEKKjXmT/22dfk5eZg+IHo= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hcl/v2 v2.12.0 h1:PsYxySWpMD4KPaoJLnsHwtK5Qptvj/4Q6s0t4sUxZf4= @@ -43,10 +43,8 @@ github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3v github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM= github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= -github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -63,7 +61,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= @@ -79,7 +76,6 @@ github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUA github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g= golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= From 5d5226df98e5d61b45d6d2e68a69f7ca2d854c75 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Jun 2022 22:16:57 +0000 Subject: [PATCH 04/33] build(deps): bump github.com/stretchr/testify from 1.7.2 to 1.7.4 Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.2 to 1.7.4. - [Release notes](https://github.com/stretchr/testify/releases) - [Commits](https://github.com/stretchr/testify/compare/v1.7.2...v1.7.4) --- updated-dependencies: - dependency-name: github.com/stretchr/testify dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index b47d6d5..ab47f2b 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/json-iterator/go v1.1.12 github.com/mitchellh/mapstructure v1.5.0 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/stretchr/testify v1.7.2 + github.com/stretchr/testify v1.7.4 github.com/yosuke-furukawa/json5 v0.1.1 golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 8f0890b..3ebc1e5 100644 --- a/go.sum +++ b/go.sum @@ -58,11 +58,14 @@ github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +github.com/stretchr/testify v1.7.4 h1:wZRexSlwd7ZXfKINDLsO4r7WBt3gTKONc6K/VesHvHM= +github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= From c69629b317daf5171cf3b223ebe1510348fbf301 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 23 Jun 2022 03:55:08 +0000 Subject: [PATCH 05/33] build(deps): bump github.com/hashicorp/hcl/v2 from 2.12.0 to 2.13.0 Bumps [github.com/hashicorp/hcl/v2](https://github.com/hashicorp/hcl) from 2.12.0 to 2.13.0. - [Release notes](https://github.com/hashicorp/hcl/releases) - [Changelog](https://github.com/hashicorp/hcl/blob/main/CHANGELOG.md) - [Commits](https://github.com/hashicorp/hcl/compare/v2.12.0...v2.13.0) --- updated-dependencies: - dependency-name: github.com/hashicorp/hcl/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index ab47f2b..d9b19ed 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/gookit/goutil v0.5.4 github.com/gookit/ini/v2 v2.1.1 github.com/hashicorp/hcl v1.0.0 - github.com/hashicorp/hcl/v2 v2.12.0 + github.com/hashicorp/hcl/v2 v2.13.0 github.com/imdario/mergo v0.3.13 github.com/json-iterator/go v1.1.12 github.com/mitchellh/mapstructure v1.5.0 diff --git a/go.sum b/go.sum index 3ebc1e5..6cb8bf2 100644 --- a/go.sum +++ b/go.sum @@ -28,8 +28,8 @@ github.com/gookit/ini/v2 v2.1.1 h1:q2VtSSl/ivTOZMPvxhjWxO3f146NvWM84jBQZETj/1o= github.com/gookit/ini/v2 v2.1.1/go.mod h1:zkMTCrnE2QgDW0izB/pRtgEKKjXmT/22dfk5eZg+IHo= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hashicorp/hcl/v2 v2.12.0 h1:PsYxySWpMD4KPaoJLnsHwtK5Qptvj/4Q6s0t4sUxZf4= -github.com/hashicorp/hcl/v2 v2.12.0/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg= +github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc= +github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0= github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= @@ -78,30 +78,33 @@ github.com/zclconf/go-cty v1.8.0 h1:s4AvqaeQzJIu3ndv4gVIhplVD0krU+bgrcLSVUnaWuA= github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g= golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167 h1:O8uGbHCqlTp2P6QJSLmCojM4mN6UemYv8K+dCnmHmu0= +golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/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-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/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-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= From 20371c236fe64fe8266081ae0557b1cd671e74c0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 23 Jun 2022 21:39:36 +0000 Subject: [PATCH 06/33] build(deps): bump github.com/gookit/goutil from 0.5.4 to 0.5.5 Bumps [github.com/gookit/goutil](https://github.com/gookit/goutil) from 0.5.4 to 0.5.5. - [Release notes](https://github.com/gookit/goutil/releases) - [Commits](https://github.com/gookit/goutil/compare/v0.5.4...v0.5.5) --- updated-dependencies: - dependency-name: github.com/gookit/goutil dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d9b19ed..70531a7 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( github.com/BurntSushi/toml v1.1.0 - github.com/gookit/goutil v0.5.4 + github.com/gookit/goutil v0.5.5 github.com/gookit/ini/v2 v2.1.1 github.com/hashicorp/hcl v1.0.0 github.com/hashicorp/hcl/v2 v2.13.0 diff --git a/go.sum b/go.sum index 6cb8bf2..7d1670e 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ= github.com/gookit/color v1.5.1/go.mod h1:wZFzea4X8qN6vHOSP2apMb4/+w/orMznEzYsIHPaqKM= github.com/gookit/goutil v0.5.3/go.mod h1:W0rVeVN9EcoRV+ODq91TXvqoUA87BXGi36WFVykCKRI= -github.com/gookit/goutil v0.5.4 h1:SUorRYjdeNyAP0f4w0VDh4J6N3V72j0Iium6fP+xhb4= -github.com/gookit/goutil v0.5.4/go.mod h1:NQJY4PEwCCW27s4bIxjEJQbsPnsxVhQqRF2xU6L3Qrk= +github.com/gookit/goutil v0.5.5 h1:poRlymIRJ+X++eWAsbqge7lZptrqqfwU6jtvRDC/HeM= +github.com/gookit/goutil v0.5.5/go.mod h1:FqRBhxNAGeHQKODXK6yfT3TR5jZiJH2W3QF5H+pRkvg= github.com/gookit/ini/v2 v2.1.1 h1:q2VtSSl/ivTOZMPvxhjWxO3f146NvWM84jBQZETj/1o= github.com/gookit/ini/v2 v2.1.1/go.mod h1:zkMTCrnE2QgDW0izB/pRtgEKKjXmT/22dfk5eZg+IHo= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= From 01bcf977dea65533dd6d27fc56ea5a7ba8e1ed32 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 24 Jun 2022 21:44:07 +0000 Subject: [PATCH 07/33] build(deps): bump github.com/stretchr/testify from 1.7.4 to 1.7.5 Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.4 to 1.7.5. - [Release notes](https://github.com/stretchr/testify/releases) - [Commits](https://github.com/stretchr/testify/compare/v1.7.4...v1.7.5) --- updated-dependencies: - dependency-name: github.com/stretchr/testify dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 70531a7..16e11c3 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/json-iterator/go v1.1.12 github.com/mitchellh/mapstructure v1.5.0 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/stretchr/testify v1.7.4 + github.com/stretchr/testify v1.7.5 github.com/yosuke-furukawa/json5 v0.1.1 golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 7d1670e..01e17a8 100644 --- a/go.sum +++ b/go.sum @@ -64,8 +64,9 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -github.com/stretchr/testify v1.7.4 h1:wZRexSlwd7ZXfKINDLsO4r7WBt3gTKONc6K/VesHvHM= github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.7.5 h1:s5PTfem8p8EbKQOctVV53k6jCJt3UX4IEJzwh+C324Q= +github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= From 8d5bb4afe345e330b802f9187ad74616fb3bc961 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 29 Jun 2022 21:53:48 +0000 Subject: [PATCH 08/33] build(deps): bump github.com/stretchr/testify from 1.7.5 to 1.8.0 Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.5 to 1.8.0. - [Release notes](https://github.com/stretchr/testify/releases) - [Commits](https://github.com/stretchr/testify/compare/v1.7.5...v1.8.0) --- updated-dependencies: - dependency-name: github.com/stretchr/testify dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 16e11c3..ddf1c36 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/json-iterator/go v1.1.12 github.com/mitchellh/mapstructure v1.5.0 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/stretchr/testify v1.7.5 + github.com/stretchr/testify v1.8.0 github.com/yosuke-furukawa/json5 v0.1.1 golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 01e17a8..1ef5761 100644 --- a/go.sum +++ b/go.sum @@ -65,8 +65,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.7.5 h1:s5PTfem8p8EbKQOctVV53k6jCJt3UX4IEJzwh+C324Q= -github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= From 4806a21eee4a61c8cc75816c1ad1fcd2fb59d8d4 Mon Sep 17 00:00:00 2001 From: Inhere Date: Mon, 4 Jul 2022 17:55:45 +0800 Subject: [PATCH 09/33] chore: update some gh action script and method comments --- .github/changelog.yml | 3 ++- .github/workflows/release.yml | 2 +- load.go | 1 + util.go | 6 ++++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/changelog.yml b/.github/changelog.yml index 02b2d50..8d3c7dd 100644 --- a/.github/changelog.yml +++ b/.github/changelog.yml @@ -3,7 +3,8 @@ title: '## Change Log' style: gh-release # group names names: [Refactor, Fixed, Feature, Update, Other] -repo_url: https://github.com/gookit/config +# if empty will auto fetch by git remote +#repo_url: https://github.com/gookit/config filters: # message length should >= 12 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b0e6eee..5443249 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,7 +36,7 @@ jobs: - name: Generate changelog run: | go install github.com/gookit/gitw/cmd/chlog@latest - chlog -config .github/changelog.yml -output testdata/changelog.md prev last + chlog -c .github/changelog.yml -o testdata/changelog.md prev last # https://github.com/softprops/action-gh-release - name: Create release and upload assets diff --git a/load.go b/load.go index 8895a03..4c1a850 100644 --- a/load.go +++ b/load.go @@ -106,6 +106,7 @@ var validTypes = map[string]int{ func LoadFlags(keys []string) error { return dc.LoadFlags(keys) } // LoadFlags parse command line arguments, based on provide keys. +// // Usage: // // debug flag is bool type // c.LoadFlags([]string{"env", "debug:bool"}) diff --git a/util.go b/util.go index a94a616..f7fa89d 100644 --- a/util.go +++ b/util.go @@ -77,12 +77,18 @@ func (c *Config) SetEncoders(encoders map[string]Encoder) { * helper methods/functions *************************************************************/ +// LoadENVFiles load +// func LoadENVFiles(filePaths ...string) error { +// return dotenv.LoadFiles(filePaths...) +// } + // GetEnv get os ENV value by name func GetEnv(name string, defVal ...string) (val string) { return Getenv(name, defVal...) } // Getenv get os ENV value by name. like os.Getenv, but support default value +// // Notice: // - Key is not case-sensitive when getting func Getenv(name string, defVal ...string) (val string) { From 046bdd78d2484736b695743fe2fa1a0edb5f203f Mon Sep 17 00:00:00 2001 From: Inhere Date: Mon, 4 Jul 2022 20:15:19 +0800 Subject: [PATCH 10/33] feat: new option - ParseTime support parse string to time.Duration. see issue#81 --- README.md | 3 +++ README.zh-CN.md | 3 +++ export.go | 8 ++++---- issues_test.go | 38 ++++++++++++++++++++++++++++++++++++++ options.go | 32 +++++++++++++++++++++----------- util.go | 24 +++++++++++++++++++++--- 6 files changed, 90 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 3660891..d8e18f0 100644 --- a/README.md +++ b/README.md @@ -306,6 +306,9 @@ ioutil.WriteFile("my-config.yaml", buf.Bytes(), 0755) type Options struct { // parse env value. like: "${EnvName}" "${EnvName|default}" ParseEnv bool + // ParseTime parses a duration string to time.Duration + // eg: 10s, 2m + ParseTime bool // config is readonly. default is False Readonly bool // enable config data cache. default is False diff --git a/README.zh-CN.md b/README.zh-CN.md index c89157c..e41af2d 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -288,6 +288,9 @@ ioutil.WriteFile("my-config.yaml", buf.Bytes(), 0755) type Options struct { // parse env value. like: "${EnvName}" "${EnvName|default}" ParseEnv bool + // ParseTime parses a duration string to time.Duration + // eg: 10s, 2m + ParseTime bool // config is readonly. default is False Readonly bool // enable config data cache. default is False diff --git a/export.go b/export.go index e9a2f83..faaccd8 100644 --- a/export.go +++ b/export.go @@ -66,15 +66,15 @@ func (c *Config) Structure(key string, dst interface{}) error { bindConf = newDefaultDecoderConfig() } else { bindConf = c.opts.DecoderConfig - // Compatible with previous settings opts.TagName + // compatible with previous settings opts.TagName if bindConf.TagName == "" { bindConf.TagName = c.opts.TagName } } - // parse env var - if c.opts.ParseEnv && bindConf.DecodeHook == nil { - bindConf.DecodeHook = ParseEnvVarStringHookFunc() + // add hook on decode value to struct + if bindConf.DecodeHook == nil && c.opts.shouldAddHookFunc() { + bindConf.DecodeHook = ValDecodeHookFunc(c.opts.ParseEnv, c.opts.ParseTime) } bindConf.Result = dst // set result struct ptr diff --git a/issues_test.go b/issues_test.go index f92f90b..b311fec 100644 --- a/issues_test.go +++ b/issues_test.go @@ -2,6 +2,7 @@ package config_test import ( "testing" + "time" "github.com/gookit/config/v2" "github.com/gookit/config/v2/ini" @@ -162,3 +163,40 @@ func TestIssues_76(t *testing.T) { is.Equal("value cannot be convert to []string, key is 'key0'", lastErr.Error()) is.NoError(c.Error()) } + +// https://github.com/gookit/config/issues/81 +func TestIssues_81(t *testing.T) { + is := assert.New(t) + c := config.New("test").WithOptions(config.ParseTime, func(options *config.Options) { + options.DecoderConfig.TagName = "json" + }) + + err := c.LoadStrings(config.JSON, ` +{ + "key0": "abc", + "age": 12, + "connTime": "10s", + "idleTime": "1m" +} +`) + is.NoError(err) + + type Options struct { + ConnTime time.Duration `json:"connTime"` + IdleTime time.Duration `json:"idleTime"` + } + + opt := &Options{} + err = c.BindStruct("", opt) + + is.NoError(err) + is.Equal("10s", c.String("connTime")) + wantTm, err := time.ParseDuration("10s") + is.NoError(err) + is.Equal(wantTm, opt.ConnTime) + + is.Equal("1m", c.String("idleTime")) + wantTm, err = time.ParseDuration("1m") + is.NoError(err) + is.Equal(wantTm, opt.IdleTime) +} diff --git a/options.go b/options.go index 2c02b82..f2a02d8 100644 --- a/options.go +++ b/options.go @@ -15,24 +15,27 @@ type HookFunc func(event string, c *Config) // Options config options type Options struct { - // parse env value. like: "${EnvName}" "${EnvName|default}" + // ParseEnv parse env value. like: "${EnvName}" "${EnvName|default}" ParseEnv bool - // config is readonly + // ParseTime parses a duration string to time.Duration + // eg: 10s, 2m + ParseTime bool + // Readonly config is readonly Readonly bool - // enable config data cache + // EnableCache enable config data cache EnableCache bool - // parse key, allow find value by key path. eg: 'key.sub' will find `map[key]sub` + // ParseKey parse key path, allow find value by key path. eg: 'key.sub' will find `map[key]sub` ParseKey bool - // tag name for binding data to struct + // TagName tag name for binding data to struct // Deprecated: please set tag name by DecoderConfig TagName string - // the delimiter char for split key path, if `FindByPath=true`. default is '.' + // Delimiter the delimiter char for split key path, if `FindByPath=true`. default is '.' Delimiter byte - // default write format + // DumpFormat default write format DumpFormat string - // default input format + // ReadFormat default input format ReadFormat string - // DecoderConfig setting for binding data to struct + // DecoderConfig setting for binding data to struct. such as: TagName DecoderConfig *mapstructure.DecoderConfig // HookFunc on data changed. HookFunc HookFunc @@ -57,17 +60,24 @@ func newDefaultDecoderConfig() *mapstructure.DecoderConfig { TagName: defaultStructTag, // will auto convert string to int/uint WeaklyTypedInput: true, - // DecodeHook: ParseEnvVarStringHookFunc, + // DecodeHook: ValDecodeHookFunc, } } +func (o *Options) shouldAddHookFunc() bool { + return o.ParseTime || o.ParseEnv +} + /************************************************************* * config setting *************************************************************/ -// ParseEnv set parse env +// ParseEnv set parse env value func ParseEnv(opts *Options) { opts.ParseEnv = true } +// ParseTime set parse time string. +func ParseTime(opts *Options) { opts.ParseTime = true } + // Readonly set readonly func Readonly(opts *Options) { opts.Readonly = true } diff --git a/util.go b/util.go index f7fa89d..5b3b53c 100644 --- a/util.go +++ b/util.go @@ -4,19 +4,37 @@ import ( "os" "reflect" "strings" + "time" "github.com/gookit/goutil/envutil" "github.com/mitchellh/mapstructure" ) -// ParseEnvVarStringHookFunc returns a DecodeHookFunc that parse ENV var -func ParseEnvVarStringHookFunc() mapstructure.DecodeHookFunc { +// ValDecodeHookFunc returns a mapstructure.DecodeHookFunc that parse ENV var, and more custom parse +func ValDecodeHookFunc(parseEnv, parseTime bool) mapstructure.DecodeHookFunc { return func(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error) { if f.Kind() != reflect.String { return data, nil } - str := envutil.ParseEnvValue(data.(string)) + str := data.(string) + if len(str) < 2 { + return str, nil + } + + // start char is number(1-9) + if str[0] > 48 && str[0] < 57 { + // parse time string. eg: 10s + if parseTime && t.Kind() == reflect.Int64 { + dur, err := time.ParseDuration(str) + if err == nil { + return dur, nil + } + } + } else if parseEnv { // parse ENV value + str = envutil.ParseEnvValue(str) + } + return str, nil } } From 46dc4507e86cb8d9f60ef407e5d656a4697d1b45 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Jul 2022 21:45:05 +0000 Subject: [PATCH 11/33] build(deps): bump github.com/gookit/goutil from 0.5.5 to 0.5.6 Bumps [github.com/gookit/goutil](https://github.com/gookit/goutil) from 0.5.5 to 0.5.6. - [Release notes](https://github.com/gookit/goutil/releases) - [Commits](https://github.com/gookit/goutil/compare/v0.5.5...v0.5.6) --- updated-dependencies: - dependency-name: github.com/gookit/goutil dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index ddf1c36..e62ed3c 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( github.com/BurntSushi/toml v1.1.0 - github.com/gookit/goutil v0.5.5 + github.com/gookit/goutil v0.5.6 github.com/gookit/ini/v2 v2.1.1 github.com/hashicorp/hcl v1.0.0 github.com/hashicorp/hcl/v2 v2.13.0 diff --git a/go.sum b/go.sum index 1ef5761..cfe4d42 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ= github.com/gookit/color v1.5.1/go.mod h1:wZFzea4X8qN6vHOSP2apMb4/+w/orMznEzYsIHPaqKM= github.com/gookit/goutil v0.5.3/go.mod h1:W0rVeVN9EcoRV+ODq91TXvqoUA87BXGi36WFVykCKRI= -github.com/gookit/goutil v0.5.5 h1:poRlymIRJ+X++eWAsbqge7lZptrqqfwU6jtvRDC/HeM= -github.com/gookit/goutil v0.5.5/go.mod h1:FqRBhxNAGeHQKODXK6yfT3TR5jZiJH2W3QF5H+pRkvg= +github.com/gookit/goutil v0.5.6 h1:cD4hr7iguIGNqBti0M6uEz5KhsoybasGby9xc+29LfI= +github.com/gookit/goutil v0.5.6/go.mod h1:Cmt+ahuf18EHMAlF6EoOUD/KAdYcD7FdVUbpZC+zTfc= github.com/gookit/ini/v2 v2.1.1 h1:q2VtSSl/ivTOZMPvxhjWxO3f146NvWM84jBQZETj/1o= github.com/gookit/ini/v2 v2.1.1/go.mod h1:zkMTCrnE2QgDW0izB/pRtgEKKjXmT/22dfk5eZg+IHo= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= @@ -64,7 +64,6 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= From 229c49d00caed77b76ebcba1762c213b43796a8b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Jul 2022 22:12:15 +0000 Subject: [PATCH 12/33] build(deps): bump github.com/gookit/goutil from 0.5.6 to 0.5.7 Bumps [github.com/gookit/goutil](https://github.com/gookit/goutil) from 0.5.6 to 0.5.7. - [Release notes](https://github.com/gookit/goutil/releases) - [Commits](https://github.com/gookit/goutil/compare/v0.5.6...v0.5.7) --- updated-dependencies: - dependency-name: github.com/gookit/goutil dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e62ed3c..a21f110 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( github.com/BurntSushi/toml v1.1.0 - github.com/gookit/goutil v0.5.6 + github.com/gookit/goutil v0.5.7 github.com/gookit/ini/v2 v2.1.1 github.com/hashicorp/hcl v1.0.0 github.com/hashicorp/hcl/v2 v2.13.0 diff --git a/go.sum b/go.sum index cfe4d42..5324481 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ= github.com/gookit/color v1.5.1/go.mod h1:wZFzea4X8qN6vHOSP2apMb4/+w/orMznEzYsIHPaqKM= github.com/gookit/goutil v0.5.3/go.mod h1:W0rVeVN9EcoRV+ODq91TXvqoUA87BXGi36WFVykCKRI= -github.com/gookit/goutil v0.5.6 h1:cD4hr7iguIGNqBti0M6uEz5KhsoybasGby9xc+29LfI= -github.com/gookit/goutil v0.5.6/go.mod h1:Cmt+ahuf18EHMAlF6EoOUD/KAdYcD7FdVUbpZC+zTfc= +github.com/gookit/goutil v0.5.7 h1:WaeQ96zRB/69ho5fOcOb1J2diRAMXX5i9Pm1z5Uh2v4= +github.com/gookit/goutil v0.5.7/go.mod h1:Cmt+ahuf18EHMAlF6EoOUD/KAdYcD7FdVUbpZC+zTfc= github.com/gookit/ini/v2 v2.1.1 h1:q2VtSSl/ivTOZMPvxhjWxO3f146NvWM84jBQZETj/1o= github.com/gookit/ini/v2 v2.1.1/go.mod h1:zkMTCrnE2QgDW0izB/pRtgEKKjXmT/22dfk5eZg+IHo= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= From 45d08075572d0612c9f131f5472ec3961718d13e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Jul 2022 22:09:00 +0000 Subject: [PATCH 13/33] build(deps): bump github.com/BurntSushi/toml from 1.1.0 to 1.2.0 Bumps [github.com/BurntSushi/toml](https://github.com/BurntSushi/toml) from 1.1.0 to 1.2.0. - [Release notes](https://github.com/BurntSushi/toml/releases) - [Commits](https://github.com/BurntSushi/toml/compare/v1.1.0...v1.2.0) --- updated-dependencies: - dependency-name: github.com/BurntSushi/toml dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index a21f110..38a62bc 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/gookit/config/v2 go 1.15 require ( - github.com/BurntSushi/toml v1.1.0 + github.com/BurntSushi/toml v1.2.0 github.com/gookit/goutil v0.5.7 github.com/gookit/ini/v2 v2.1.1 github.com/hashicorp/hcl v1.0.0 diff --git a/go.sum b/go.sum index 5324481..1e8e16f 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= -github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= +github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8= github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= From 06a328eb6a1909fa9c5615696136e6bf8e08312b Mon Sep 17 00:00:00 2001 From: "g.ph" Date: Fri, 22 Jul 2022 14:33:12 +0800 Subject: [PATCH 14/33] add DumpToFile add WithSetSaveFile --- export.go | 38 ++++++++++++++++++++++++++++++++++---- options.go | 23 ++++++++++++++++++++--- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/export.go b/export.go index faaccd8..c4c904a 100644 --- a/export.go +++ b/export.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io" + "os" "github.com/mitchellh/mapstructure" ) @@ -12,8 +13,9 @@ import ( // MapStruct alias method of the 'Structure' // // Usage: -// dbInfo := &Db{} -// config.MapStruct("db", dbInfo) +// +// dbInfo := &Db{} +// config.MapStruct("db", dbInfo) func MapStruct(key string, dst interface{}) error { return dc.MapStruct(key, dst) } // MapStruct alias method of the 'Structure' @@ -47,8 +49,9 @@ func (c *Config) MapOnExists(key string, dst interface{}) error { // Structure get config data and binding to the dst structure. // // Usage: -// dbInfo := Db{} -// config.Structure("db", &dbInfo) +// +// dbInfo := Db{} +// config.Structure("db", &dbInfo) func (c *Config) Structure(key string, dst interface{}) error { var data interface{} if key == "" { // binding all data @@ -136,3 +139,30 @@ func (c *Config) DumpTo(out io.Writer, format string) (n int64, err error) { return int64(num), nil } + +// DumpToFile use the format(json,yaml,toml) dump config data to a writer +func (c *Config) DumpToFile(fileName string, format string) (err error) { + var ok bool + var encoder Encoder + + format = fixFormat(format) + if encoder, ok = c.encoders[format]; !ok { + err = errors.New("not exists/register encoder for the format: " + format) + return + } + + // is empty + if len(c.data) == 0 { + return + } + + // encode data to string + encoded, err := encoder(c.data) + if err != nil { + return + } + + // write content to out + //num, _ := fmt.Fprintln(out, string(encoded)) + return os.WriteFile(fileName, encoded, os.ModePerm) +} diff --git a/options.go b/options.go index f2a02d8..545ad78 100644 --- a/options.go +++ b/options.go @@ -1,6 +1,9 @@ package config -import "github.com/mitchellh/mapstructure" +import ( + "github.com/mitchellh/mapstructure" + "strings" +) // there are some event names for config data changed. const ( @@ -88,6 +91,19 @@ func Delimiter(sep byte) func(*Options) { } } +func WithSetSaveFile(fileName string, format string) func(options *Options) { + return func(opts *Options) { + opts.HookFunc = func(event string, c *Config) { + if strings.HasPrefix(event, "set.") { + err := c.DumpToFile(fileName, format) + if err != nil { + panic(err) + } + } + } + } +} + // WithHookFunc set hook func func WithHookFunc(fn HookFunc) func(*Options) { return func(opts *Options) { @@ -131,8 +147,9 @@ func (c *Config) With(fn func(c *Config)) *Config { // Readonly disable set data to config. // // Usage: -// config.LoadFiles(a, b, c) -// config.Readonly() +// +// config.LoadFiles(a, b, c) +// config.Readonly() func (c *Config) Readonly() { c.opts.Readonly = true } From ad9cf78235247b8a5622cb77539be6fa61428560 Mon Sep 17 00:00:00 2001 From: Inhere Date: Fri, 22 Jul 2022 16:10:41 +0800 Subject: [PATCH 15/33] Create codeql.yml --- .github/workflows/codeql.yml | 72 ++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..c3cf23c --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,72 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ "master" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "master" ] + schedule: + - cron: '40 14 * * 6' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 From 38ad9f8577bbef286ff22b4b4b313dcf67b89245 Mon Sep 17 00:00:00 2001 From: "g.ph" Date: Thu, 28 Jul 2022 13:13:07 +0800 Subject: [PATCH 16/33] add WithSetSaveFile comments --- options.go | 1 + 1 file changed, 1 insertion(+) diff --git a/options.go b/options.go index 545ad78..a411743 100644 --- a/options.go +++ b/options.go @@ -91,6 +91,7 @@ func Delimiter(sep byte) func(*Options) { } } +// WithSetSaveFile set hook func func WithSetSaveFile(fileName string, format string) func(options *Options) { return func(opts *Options) { opts.HookFunc = func(event string, c *Config) { From b427382feb1188ff23bf67a73948154454dfbe7f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 Aug 2022 21:50:57 +0000 Subject: [PATCH 17/33] build(deps): bump morphy2k/revive-action from 2.3.1 to 2.4.0 Bumps [morphy2k/revive-action](https://github.com/morphy2k/revive-action) from 2.3.1 to 2.4.0. - [Release notes](https://github.com/morphy2k/revive-action/releases) - [Commits](https://github.com/morphy2k/revive-action/compare/v2.3.1...v2.4.0) --- updated-dependencies: - dependency-name: morphy2k/revive-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 83b0e91..804f4fd 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -31,7 +31,7 @@ jobs: go-version: ${{ matrix.go_version }} - name: Revive check - uses: morphy2k/revive-action@v2.3.1 + uses: morphy2k/revive-action@v2.4.0 with: # Exclude patterns, separated by semicolons (optional) exclude: "./_examples/..." From 9764bbd6c0bd0d07488f5dcd62013b2fa81b0683 Mon Sep 17 00:00:00 2001 From: Inhere Date: Mon, 1 Aug 2022 19:42:12 +0800 Subject: [PATCH 18/33] fix: retry set value error on load yaml v2 data --- write.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/write.go b/write.go index d056c05..e154280 100644 --- a/write.go +++ b/write.go @@ -74,8 +74,8 @@ func (c *Config) Set(key string, val interface{}, setByPath ...bool) (err error) } switch typeData := item.(type) { - case map[interface{}]interface{}: // from yaml - dstItem := make(map[string]interface{}) + case map[interface{}]interface{}: // from yaml.v2 + dstItem := make(map[interface{}]interface{}, len(typeData)) for k, v := range typeData { sk := fmt.Sprintf("%v", k) dstItem[sk] = v @@ -90,7 +90,7 @@ func (c *Config) Set(key string, val interface{}, setByPath ...bool) (err error) } c.data[topK] = dstItem - case map[string]interface{}: // from json,toml + case map[string]interface{}: // from json,toml,yaml.v3 // create a new item for the topK newItem := buildValueByPath(paths, val) // merge new item to old item From 1ca5fff769e60f862946805a0326748931ce1d04 Mon Sep 17 00:00:00 2001 From: Inhere Date: Tue, 9 Aug 2022 13:34:18 +0800 Subject: [PATCH 19/33] fix: #91 - add lock on binding values to struct --- export.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/export.go b/export.go index c4c904a..11a73bf 100644 --- a/export.go +++ b/export.go @@ -64,6 +64,10 @@ func (c *Config) Structure(key string, dst interface{}) error { } } + // add lock on binding values to struct + c.lock.RLock() + defer c.lock.RUnlock() + var bindConf *mapstructure.DecoderConfig if c.opts.DecoderConfig == nil { bindConf = newDefaultDecoderConfig() From 4ed0a18f27a19f53c656a8f8ed7ec9c296adb064 Mon Sep 17 00:00:00 2001 From: Inhere Date: Tue, 9 Aug 2022 13:36:17 +0800 Subject: [PATCH 20/33] feat: add new driver use Java properties as config source --- go.mod | 1 + go.sum | 2 ++ properties/properties.go | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 properties/properties.go diff --git a/go.mod b/go.mod index 38a62bc..8c3b6ac 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/BurntSushi/toml v1.2.0 github.com/gookit/goutil v0.5.7 github.com/gookit/ini/v2 v2.1.1 + github.com/gookit/properties v0.0.0-20220808091034-7fbd8454e142 github.com/hashicorp/hcl v1.0.0 github.com/hashicorp/hcl/v2 v2.13.0 github.com/imdario/mergo v0.3.13 diff --git a/go.sum b/go.sum index 1e8e16f..73b0b82 100644 --- a/go.sum +++ b/go.sum @@ -26,6 +26,8 @@ github.com/gookit/goutil v0.5.7 h1:WaeQ96zRB/69ho5fOcOb1J2diRAMXX5i9Pm1z5Uh2v4= github.com/gookit/goutil v0.5.7/go.mod h1:Cmt+ahuf18EHMAlF6EoOUD/KAdYcD7FdVUbpZC+zTfc= github.com/gookit/ini/v2 v2.1.1 h1:q2VtSSl/ivTOZMPvxhjWxO3f146NvWM84jBQZETj/1o= github.com/gookit/ini/v2 v2.1.1/go.mod h1:zkMTCrnE2QgDW0izB/pRtgEKKjXmT/22dfk5eZg+IHo= +github.com/gookit/properties v0.0.0-20220808091034-7fbd8454e142 h1:++rGX59M6pDVifR9XTWKYkHFIGjeIJ2a7yIWpoCSwZI= +github.com/gookit/properties v0.0.0-20220808091034-7fbd8454e142/go.mod h1:5bQJ+BPO2n22tZWV4IWT6PiN2U5OJJAY/omLhz5LyK4= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc= diff --git a/properties/properties.go b/properties/properties.go new file mode 100644 index 0000000..e793829 --- /dev/null +++ b/properties/properties.go @@ -0,0 +1,26 @@ +/* +Package properties is a driver use Java properties format content as config source + +Usage please see readme. + +*/ +package properties + +import ( + "github.com/gookit/config/v2" + "github.com/gookit/properties" +) + +// DriverName string +const DriverName = "properties" + +var ( + // Decoder the properties content decoder + Decoder config.Decoder = properties.Decode + + // Encoder the properties content encoder + Encoder config.Encoder = properties.Encode + + // Driver for yaml + Driver = config.NewDriver(DriverName, Decoder, Encoder) +) From adc55a99ccb0b73beb41a8ad00ad506a0e444339 Mon Sep 17 00:00:00 2001 From: Inhere Date: Tue, 9 Aug 2022 13:36:38 +0800 Subject: [PATCH 21/33] chore: update some code style and comments --- config.go | 12 +++--------- options.go | 2 +- other/other.go | 5 +++-- util.go | 2 +- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/config.go b/config.go index bf2f326..5c0a6ef 100644 --- a/config.go +++ b/config.go @@ -186,9 +186,7 @@ func (c *Config) DelDriver(format string) { *************************************************************/ // Name get config name -func (c *Config) Name() string { - return c.name -} +func (c *Config) Name() string { return c.name } // Error get last error, will clear after read. func (c *Config) Error() error { @@ -203,14 +201,10 @@ func (c *Config) IsEmpty() bool { } // LoadedFiles get loaded files name -func (c *Config) LoadedFiles() []string { - return c.loadedFiles -} +func (c *Config) LoadedFiles() []string { return c.loadedFiles } // DriverNames get loaded driver names -func (c *Config) DriverNames() []string { - return c.driverNames -} +func (c *Config) DriverNames() []string { return c.driverNames } // ClearAll data and caches func ClearAll() { dc.ClearAll() } diff --git a/options.go b/options.go index a411743..ee84919 100644 --- a/options.go +++ b/options.go @@ -42,6 +42,7 @@ type Options struct { DecoderConfig *mapstructure.DecoderConfig // HookFunc on data changed. HookFunc HookFunc + // WatchChange bool } func newDefaultOption() *Options { @@ -63,7 +64,6 @@ func newDefaultDecoderConfig() *mapstructure.DecoderConfig { TagName: defaultStructTag, // will auto convert string to int/uint WeaklyTypedInput: true, - // DecodeHook: ValDecodeHookFunc, } } diff --git a/other/other.go b/other/other.go index 8fbca74..99c4b84 100644 --- a/other/other.go +++ b/other/other.go @@ -8,7 +8,8 @@ import ( "github.com/gookit/config/v2/ini" ) -const driverName = "other" +// DriverName string +const DriverName = "other" var ( // Encoder is the encoder for this driver @@ -16,5 +17,5 @@ var ( // Decoder is the decoder for this driver Decoder = ini.Decoder // Driver is the exported symbol - Driver = config.NewDriver(driverName, Decoder, Encoder) + Driver = config.NewDriver(DriverName, Decoder, Encoder) ) diff --git a/util.go b/util.go index 5b3b53c..d9143b3 100644 --- a/util.go +++ b/util.go @@ -23,7 +23,7 @@ func ValDecodeHookFunc(parseEnv, parseTime bool) mapstructure.DecodeHookFunc { } // start char is number(1-9) - if str[0] > 48 && str[0] < 57 { + if str[0] > '0' && str[0] < '9' { // parse time string. eg: 10s if parseTime && t.Kind() == reflect.Int64 { dur, err := time.ParseDuration(str) From 8021f6cc8d0a07af9d45c78fb5b76fb2da79abaa Mon Sep 17 00:00:00 2001 From: Inhere Date: Tue, 9 Aug 2022 23:39:50 +0800 Subject: [PATCH 22/33] fix: fix DumpToFile() error on go1.15, add some tests --- config_test.go | 18 ++++++++++++++++++ export.go | 14 +++++++++++--- options.go | 7 ++++--- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/config_test.go b/config_test.go index 8a1522c..55fdcb6 100644 --- a/config_test.go +++ b/config_test.go @@ -403,6 +403,24 @@ func TestJSONAllowComments(t *testing.T) { JSONAllowComments = old } +func TestSaveFileOnSet(t *testing.T) { + old := JSONMarshalIndent + JSONMarshalIndent = " " + defer func() { + JSONMarshalIndent = old + }() + + is := assert.New(t) + c := New("test") + c.WithOptions(SaveFileOnSet("testdata/config.bak.json", JSON)) + + err := c.LoadStrings(JSON, jsonStr) + is.Nil(err) + + is.NoError(c.Set("new-key", "new-value")) + is.Equal("new-value", c.Get("new-key")) +} + func TestMapStringStringParseEnv(t *testing.T) { is := assert.New(t) c := New("test") diff --git a/export.go b/export.go index 11a73bf..e4473c6 100644 --- a/export.go +++ b/export.go @@ -155,7 +155,6 @@ func (c *Config) DumpToFile(fileName string, format string) (err error) { return } - // is empty if len(c.data) == 0 { return } @@ -167,6 +166,15 @@ func (c *Config) DumpToFile(fileName string, format string) (err error) { } // write content to out - //num, _ := fmt.Fprintln(out, string(encoded)) - return os.WriteFile(fileName, encoded, os.ModePerm) + fsFlags := os.O_CREATE | os.O_WRONLY | os.O_TRUNC + f, err := os.OpenFile(fileName, fsFlags, os.ModePerm) + if err != nil { + return err + } + + _, err = f.Write(encoded) + if err1 := f.Close(); err1 != nil && err == nil { + err = err1 + } + return err } diff --git a/options.go b/options.go index ee84919..a436391 100644 --- a/options.go +++ b/options.go @@ -1,8 +1,9 @@ package config import ( - "github.com/mitchellh/mapstructure" "strings" + + "github.com/mitchellh/mapstructure" ) // there are some event names for config data changed. @@ -91,8 +92,8 @@ func Delimiter(sep byte) func(*Options) { } } -// WithSetSaveFile set hook func -func WithSetSaveFile(fileName string, format string) func(options *Options) { +// SaveFileOnSet set hook func +func SaveFileOnSet(fileName string, format string) func(options *Options) { return func(opts *Options) { opts.HookFunc = func(event string, c *Config) { if strings.HasPrefix(event, "set.") { From 64ddf53f0b3dc4cb0f33ad8cd411a5da4c3c6887 Mon Sep 17 00:00:00 2001 From: Inhere Date: Tue, 9 Aug 2022 23:40:47 +0800 Subject: [PATCH 23/33] up: update some code style and update gh release script --- .github/changelog.yml | 8 ++++---- .github/workflows/release.yml | 15 ++++----------- go.mod | 2 +- json5/json5.go | 5 ++++- json5/json5_test.go | 8 ++++---- properties/properties.go | 8 ++++---- 6 files changed, 21 insertions(+), 25 deletions(-) diff --git a/.github/changelog.yml b/.github/changelog.yml index 8d3c7dd..d60b2cb 100644 --- a/.github/changelog.yml +++ b/.github/changelog.yml @@ -4,7 +4,7 @@ style: gh-release # group names names: [Refactor, Fixed, Feature, Update, Other] # if empty will auto fetch by git remote -#repo_url: https://github.com/gookit/config +#repo_url: https://github.com/gookit/goutil filters: # message length should >= 12 @@ -31,7 +31,7 @@ rules: contains: ['fix:'] - name: Feature start_withs: [feat, new] - contains: [feature] + contains: [feature, 'feat:'] - name: Update - start_withs: [update, 'up:'] - contains: [' update'] + start_withs: [up] + contains: ['update:', 'up:'] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5443249..0334f18 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,8 +12,6 @@ jobs: timeout-minutes: 10 strategy: fail-fast: true - matrix: - go_version: [1.17] steps: - name: Checkout @@ -21,12 +19,6 @@ jobs: with: fetch-depth: 0 - - name: Setup Go Faster - uses: WillAbides/setup-go-faster@v1.7.0 - timeout-minutes: 3 - with: - go-version: ${{ matrix.go_version }} - - name: Setup ENV # https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable run: | @@ -35,8 +27,9 @@ jobs: - name: Generate changelog run: | - go install github.com/gookit/gitw/cmd/chlog@latest - chlog -c .github/changelog.yml -o testdata/changelog.md prev last + curl https://github.com/gookit/gitw/releases/latest/download/chlog-linux-amd64 -L -o /usr/local/bin/chlog + chmod a+x /usr/local/bin/chlog + chlog -c .github/changelog.yml -o changelog.md prev last # https://github.com/softprops/action-gh-release - name: Create release and upload assets @@ -46,6 +39,6 @@ jobs: with: name: ${{ env.RELEASE_TAG }} tag_name: ${{ env.RELEASE_TAG }} - body_path: testdata/changelog.md + body_path: changelog.md token: ${{ secrets.GITHUB_TOKEN }} # files: macos-chlog.exe diff --git a/go.mod b/go.mod index 8c3b6ac..359815b 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/gookit/config/v2 -go 1.15 +go 1.16 require ( github.com/BurntSushi/toml v1.2.0 diff --git a/json5/json5.go b/json5/json5.go index 6a89180..46d3265 100644 --- a/json5/json5.go +++ b/json5/json5.go @@ -9,6 +9,9 @@ import ( // NAME for driver const NAME = "json5" +// Name for driver +const Name = "json5" + // JSONMarshalIndent if not empty, will use json.MarshalIndent for encode data. var JSONMarshalIndent string @@ -26,5 +29,5 @@ var ( } // Driver for json5 - Driver = config.NewDriver(NAME, Decoder, Encoder) + Driver = config.NewDriver(Name, Decoder, Encoder) ) diff --git a/json5/json5_test.go b/json5/json5_test.go index a01de7f..1974dbe 100644 --- a/json5/json5_test.go +++ b/json5/json5_test.go @@ -67,14 +67,14 @@ func Example() { func TestDriver(t *testing.T) { is := assert.New(t) - is.Equal(json5.NAME, json5.Driver.Name()) + is.Equal(json5.Name, json5.Driver.Name()) c := config.NewEmpty("test") - is.False(c.HasDecoder(json5.NAME)) + is.False(c.HasDecoder(json5.Name)) c.AddDriver(json5.Driver) - is.True(c.HasDecoder(json5.NAME)) - is.True(c.HasEncoder(json5.NAME)) + is.True(c.HasDecoder(json5.Name)) + is.True(c.HasEncoder(json5.Name)) m := struct { N string diff --git a/properties/properties.go b/properties/properties.go index e793829..54121b5 100644 --- a/properties/properties.go +++ b/properties/properties.go @@ -11,8 +11,8 @@ import ( "github.com/gookit/properties" ) -// DriverName string -const DriverName = "properties" +// Name string +const Name = "properties" var ( // Decoder the properties content decoder @@ -21,6 +21,6 @@ var ( // Encoder the properties content encoder Encoder config.Encoder = properties.Encode - // Driver for yaml - Driver = config.NewDriver(DriverName, Decoder, Encoder) + // Driver for properties + Driver = config.NewDriver(Name, Decoder, Encoder) ) From d0e34e786bd4680dd2537e45a8217e4483bf40da Mon Sep 17 00:00:00 2001 From: Inhere Date: Tue, 9 Aug 2022 23:41:28 +0800 Subject: [PATCH 24/33] chore: add unit tests for properties driver --- properties/properties_test.go | 31 +++++++++++++++++++++++++++++++ testdata/config.bak.json | 21 +++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 properties/properties_test.go create mode 100644 testdata/config.bak.json diff --git a/properties/properties_test.go b/properties/properties_test.go new file mode 100644 index 0000000..5f9343a --- /dev/null +++ b/properties/properties_test.go @@ -0,0 +1,31 @@ +package properties_test + +import ( + "testing" + + "github.com/gookit/config/v2" + "github.com/gookit/config/v2/properties" + "github.com/gookit/goutil/testutil/assert" +) + +func TestDriver(t *testing.T) { + is := assert.New(t) + is.Eq(properties.Name, properties.Driver.Name()) + + c := config.NewEmpty("test") + is.False(c.HasDecoder(properties.Name)) + c.AddDriver(properties.Driver) + + is.True(c.HasDecoder(properties.Name)) + is.True(c.HasEncoder(properties.Name)) + + // m := struct { + // N string + // }{} + // err := properties.Decoder([]byte(`{ + // // comments + // "n":"v"} + // `), &m) + // is.Nil(err) + // is.Eq("v", m.N) +} diff --git a/testdata/config.bak.json b/testdata/config.bak.json new file mode 100644 index 0000000..0a06651 --- /dev/null +++ b/testdata/config.bak.json @@ -0,0 +1,21 @@ +{ + "age": 123, + "arr1": [ + "val", + "val1", + "val2" + ], + "baseKey": "value", + "debug": true, + "envKey": "${SHELL}", + "envKey1": "${NotExist|defValue}", + "invalidEnvKey": "${noClose", + "map1": { + "key": "val", + "key1": "val1", + "key2": "val2", + "key3": "${SHELL}" + }, + "name": "app", + "new-key": "new-value" +} \ No newline at end of file From 6d5e8a616c646dafef5618d05072593a0b7c2bcf Mon Sep 17 00:00:00 2001 From: Inhere Date: Tue, 9 Aug 2022 23:53:18 +0800 Subject: [PATCH 25/33] fix: fix set error on input yaml.v2 like data --- write.go | 42 +++++++++++++++---------- write_test.go | 87 +++++++++++++++++++++++++-------------------------- 2 files changed, 68 insertions(+), 61 deletions(-) diff --git a/write.go b/write.go index e154280..354067a 100644 --- a/write.go +++ b/write.go @@ -2,10 +2,11 @@ package config import ( "errors" - "fmt" "strconv" "strings" + "github.com/gookit/goutil/arrutil" + "github.com/gookit/goutil/strutil" "github.com/imdario/mergo" ) @@ -77,15 +78,13 @@ func (c *Config) Set(key string, val interface{}, setByPath ...bool) (err error) case map[interface{}]interface{}: // from yaml.v2 dstItem := make(map[interface{}]interface{}, len(typeData)) for k, v := range typeData { - sk := fmt.Sprintf("%v", k) - dstItem[sk] = v + dstItem[strutil.QuietString(k)] = v } // create a new item for the topK - newItem := buildValueByPath(paths, val) + newItem := buildValueByPath1(paths, val) // merge new item to old item - err = mergo.Merge(&dstItem, newItem, mergo.WithOverride) - if err != nil { + if err = mergo.Merge(&dstItem, newItem, mergo.WithOverride); err != nil { return } @@ -94,13 +93,12 @@ func (c *Config) Set(key string, val interface{}, setByPath ...bool) (err error) // create a new item for the topK newItem := buildValueByPath(paths, val) // merge new item to old item - err = mergo.Merge(&typeData, &newItem, mergo.WithOverride) - if err != nil { + if err = mergo.Merge(&typeData, &newItem, mergo.WithOverride); err != nil { return } c.data[topK] = typeData - case []interface{}: // is array + case []interface{}: // is list array index, err := strconv.Atoi(keys[1]) if len(keys) == 2 && err == nil { if index <= len(typeData) { @@ -131,7 +129,7 @@ func buildValueByPath(paths []string, val interface{}) (newItem map[string]inter return map[string]interface{}{paths[0]: val} } - sliceReverse(paths) + arrutil.Reverse(paths) // multi nodes for _, p := range paths { @@ -144,12 +142,22 @@ func buildValueByPath(paths []string, val interface{}) (newItem map[string]inter return } -// reverse a slice. (slice 是引用,所以可以直接改变) -func sliceReverse(ss []string) { - ln := len(ss) - for i := 0; i < ln/2; i++ { - li := ln - i - 1 - // fmt.Println(i, "<=>", li) - ss[i], ss[li] = ss[li], ss[i] +// build new value by key paths, only for yaml.v2 +// "site.info" -> map[interface{}]map[string]val +func buildValueByPath1(paths []string, val interface{}) (newItem map[interface{}]interface{}) { + if len(paths) == 1 { + return map[interface{}]interface{}{paths[0]: val} } + + arrutil.Reverse(paths) + + // multi nodes + for _, p := range paths { + if newItem == nil { + newItem = map[interface{}]interface{}{p: val} + } else { + newItem = map[interface{}]interface{}{p: newItem} + } + } + return } diff --git a/write_test.go b/write_test.go index 069d043..b3ed10c 100644 --- a/write_test.go +++ b/write_test.go @@ -32,146 +32,145 @@ func TestSetData(t *testing.T) { } func TestSet(t *testing.T) { - st := assert.New(t) - + is := assert.New(t) c := Default() // clear old ClearAll() // err := LoadFiles("testdata/json_base.json") err := LoadStrings(JSON, jsonStr) - st.Nil(err) + is.Nil(err) val := String("name") - st.Equal("app", val) + is.Equal("app", val) // empty key err = Set("", "val") - st.Error(err) + is.Error(err) // set new value: int err = Set("newInt", 23) - if st.Nil(err) { + if is.Nil(err) { iv := Int("newInt") - st.Equal(23, iv) + is.Equal(23, iv) } // set new value: int err = Set("newBool", false) - if st.Nil(err) { + if is.Nil(err) { bv := Bool("newBool") - st.False(bv) + is.False(bv) } // set new value: string err = Set("newKey", "new val") - if st.Nil(err) { + if is.Nil(err) { val = String("newKey") - st.Equal("new val", val) + is.Equal("new val", val) } - // like yml decoded data + // like yaml.v2 decoded data err = Set("ymlLike", map[interface{}]interface{}{"k": "v"}) - st.Nil(err) + is.Nil(err) str := c.String("ymlLike.k") - st.Equal("v", str) + is.Equal("v", str) err = Set("ymlLike.nk", "nv") - st.Nil(err) + is.Nil(err) str = c.String("ymlLike.nk") - st.Equal("nv", str) + is.Equal("nv", str) // disable setByPath err = Set("some.key", "val", false) - if st.Nil(err) { + if is.Nil(err) { val = String("some") - st.Equal("", val) + is.Equal("", val) val = String("some.key") - st.Equal("val", val) + is.Equal("val", val) } // fmt.Printf("%#v\n", c.Data()) // set value err = Set("name", "new name") - if st.Nil(err) { + if is.Nil(err) { val = String("name") - st.Equal("new name", val) + is.Equal("new name", val) } // set value to arr: by path err = Set("arr1.1", "new val") - if st.Nil(err) { + if is.Nil(err) { val = String("arr1.1") - st.Equal("new val", val) + is.Equal("new val", val) } // array only support add 1 level value err = Set("arr1.1.key", "new val") - st.Error(err) + is.Error(err) // set value to map: by path err = Set("map1.key", "new val") - if st.Nil(err) { + if is.Nil(err) { val = String("map1.key") - st.Equal("new val", val) + is.Equal("new val", val) } // more path nodes err = Set("map1.info.key", "val200") - if st.Nil(err) { + if is.Nil(err) { // fmt.Printf("%v\n", c.Data()) smp := StringMap("map1.info") - st.Equal("val200", smp["key"]) + is.Equal("val200", smp["key"]) str = String("map1.info.key") - st.Equal("val200", str) + is.Equal("val200", str) } // new map err = Set("map2.key", "new val") - if st.Nil(err) { + if is.Nil(err) { val = String("map2.key") - st.Equal("new val", val) + is.Equal("new val", val) } // set new value: array(slice) err = Set("newArr", []string{"a", "b"}) - if st.Nil(err) { + if is.Nil(err) { arr := Strings("newArr") - st.Equal(`[]string{"a", "b"}`, fmt.Sprintf("%#v", arr)) + is.Equal(`[]string{"a", "b"}`, fmt.Sprintf("%#v", arr)) val = String("newArr.1") - st.Equal("b", val) + is.Equal("b", val) val = String("newArr.100") - st.Equal("", val) + is.Equal("", val) } // set new value: map err = Set("newMap", map[string]string{"k1": "a", "k2": "b"}) - if st.Nil(err) { + if is.Nil(err) { mp := StringMap("newMap") - st.NotEmpty(mp) - // st.Equal("map[k1:a k2:b]", fmt.Sprintf("%v", mp)) + is.NotEmpty(mp) + // is.Equal("map[k1:a k2:b]", fmt.Sprintf("%v", mp)) val = String("newMap.k1") - st.Equal("a", val) + is.Equal("a", val) val = String("newMap.notExist") - st.Equal("", val) + is.Equal("", val) } - st.NoError(Set("name.sub", []int{2})) + is.NoError(Set("name.sub", []int{2})) ints := Ints("name.sub") - st.Equal([]int{2}, ints) + is.Equal([]int{2}, ints) // Readonly Default().Readonly() - st.True(c.Options().Readonly) - st.Error(Set("name", "new name")) + is.True(c.Options().Readonly) + is.Error(Set("name", "new name")) } func TestSet_fireEvent(t *testing.T) { From 62ee0803396f0bea844085576372e64c65803168 Mon Sep 17 00:00:00 2001 From: Inhere Date: Tue, 9 Aug 2022 23:59:22 +0800 Subject: [PATCH 26/33] chore: update the properties driver dep version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 359815b..64fbfc1 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/BurntSushi/toml v1.2.0 github.com/gookit/goutil v0.5.7 github.com/gookit/ini/v2 v2.1.1 - github.com/gookit/properties v0.0.0-20220808091034-7fbd8454e142 + github.com/gookit/properties v0.0.0-20220809153718-db6ef1a19b3e github.com/hashicorp/hcl v1.0.0 github.com/hashicorp/hcl/v2 v2.13.0 github.com/imdario/mergo v0.3.13 diff --git a/go.sum b/go.sum index 73b0b82..d71c8bd 100644 --- a/go.sum +++ b/go.sum @@ -26,8 +26,8 @@ github.com/gookit/goutil v0.5.7 h1:WaeQ96zRB/69ho5fOcOb1J2diRAMXX5i9Pm1z5Uh2v4= github.com/gookit/goutil v0.5.7/go.mod h1:Cmt+ahuf18EHMAlF6EoOUD/KAdYcD7FdVUbpZC+zTfc= github.com/gookit/ini/v2 v2.1.1 h1:q2VtSSl/ivTOZMPvxhjWxO3f146NvWM84jBQZETj/1o= github.com/gookit/ini/v2 v2.1.1/go.mod h1:zkMTCrnE2QgDW0izB/pRtgEKKjXmT/22dfk5eZg+IHo= -github.com/gookit/properties v0.0.0-20220808091034-7fbd8454e142 h1:++rGX59M6pDVifR9XTWKYkHFIGjeIJ2a7yIWpoCSwZI= -github.com/gookit/properties v0.0.0-20220808091034-7fbd8454e142/go.mod h1:5bQJ+BPO2n22tZWV4IWT6PiN2U5OJJAY/omLhz5LyK4= +github.com/gookit/properties v0.0.0-20220809153718-db6ef1a19b3e h1:DT+o0GuumXSZH3KIj7B/CMSPau+cgfGQHxkCeAk5LGo= +github.com/gookit/properties v0.0.0-20220809153718-db6ef1a19b3e/go.mod h1:Wktc5GebCZd7ZV9quELTa9syMBI3CiuRqimltpGo2Ww= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc= From 1d28d20561056eb19a945acdfba7166bfa89ce47 Mon Sep 17 00:00:00 2001 From: Inhere Date: Fri, 12 Aug 2022 12:58:22 +0800 Subject: [PATCH 27/33] up: use copy new bind-config instead of add read-lock --- export.go | 19 +++++++++---------- options.go | 11 ++++++++--- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/export.go b/export.go index e4473c6..06e521b 100644 --- a/export.go +++ b/export.go @@ -64,15 +64,14 @@ func (c *Config) Structure(key string, dst interface{}) error { } } - // add lock on binding values to struct - c.lock.RLock() - defer c.lock.RUnlock() - var bindConf *mapstructure.DecoderConfig if c.opts.DecoderConfig == nil { - bindConf = newDefaultDecoderConfig() + bindConf = newDefaultDecoderConfig(c.opts.TagName) } else { - bindConf = c.opts.DecoderConfig + // copy new config for each binding. + copyConf := *c.opts.DecoderConfig + bindConf = ©Conf + // compatible with previous settings opts.TagName if bindConf.TagName == "" { bindConf.TagName = c.opts.TagName @@ -86,11 +85,11 @@ func (c *Config) Structure(key string, dst interface{}) error { bindConf.Result = dst // set result struct ptr decoder, err := mapstructure.NewDecoder(bindConf) - if err != nil { - return err - } - return decoder.Decode(data) + if err == nil { + err = decoder.Decode(data) + } + return err } // ToJSON string diff --git a/options.go b/options.go index a436391..f87eb23 100644 --- a/options.go +++ b/options.go @@ -31,6 +31,7 @@ type Options struct { // ParseKey parse key path, allow find value by key path. eg: 'key.sub' will find `map[key]sub` ParseKey bool // TagName tag name for binding data to struct + // // Deprecated: please set tag name by DecoderConfig TagName string // Delimiter the delimiter char for split key path, if `FindByPath=true`. default is '.' @@ -55,14 +56,18 @@ func newDefaultOption() *Options { DumpFormat: JSON, ReadFormat: JSON, // struct decoder config - DecoderConfig: newDefaultDecoderConfig(), + DecoderConfig: newDefaultDecoderConfig(""), } } -func newDefaultDecoderConfig() *mapstructure.DecoderConfig { +func newDefaultDecoderConfig(tagName string) *mapstructure.DecoderConfig { + if tagName == "" { + tagName = defaultStructTag + } + return &mapstructure.DecoderConfig{ // tag name for binding struct - TagName: defaultStructTag, + TagName: tagName, // will auto convert string to int/uint WeaklyTypedInput: true, } From 37bfe901ef2c1f2295623033539e235c70f064db Mon Sep 17 00:00:00 2001 From: Inhere Date: Fri, 19 Aug 2022 00:58:06 +0800 Subject: [PATCH 28/33] chore: update the gookit/properties to v0.1, upgrade goutil --- README.md | 3 ++- README.zh-CN.md | 3 ++- go.mod | 5 ++--- go.sum | 18 ++++++++++-------- properties/properties_test.go | 19 ++++++++++--------- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index d8e18f0..e0e3e30 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Golang's application config manage tool library. ## Features -- Support multi format: `JSON`(default), `JSON5`, `INI`, `YAML`, `TOML`, `HCL`, `ENV`, `Flags` +- Support multi format: `JSON`(default), `JSON5`, `INI`, `Properties`, `YAML`, `TOML`, `HCL`, `ENV`, `Flags` - `JSON` content support comments. will auto clear comments - Other drivers are used on demand, not used will not be loaded into the application. - Possibility to add custom driver for your specific format @@ -411,6 +411,7 @@ Check out these projects, which use https://github.com/gookit/config : ## See also - Ini parse [gookit/ini/parser](https://github.com/gookit/ini/tree/master/parser) +- Properties parse [gookit/properties](https://github.com/gookit/properties) - Json5 parse [json5](https://github.com/yosuke-furukawa/json5) - Yaml parse [go-yaml](https://github.com/go-yaml/yaml) - Toml parse [go toml](https://github.com/BurntSushi/toml) diff --git a/README.zh-CN.md b/README.zh-CN.md index e41af2d..fc62984 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -14,7 +14,7 @@ ## 功能简介 -- 支持多种格式: `JSON`(默认), `JSON5`, `INI`, `YAML`, `TOML`, `HCL`, `ENV`, `Flags` +- 支持多种格式: `JSON`(默认), `JSON5`, `INI`, `Properties`, `YAML`, `TOML`, `HCL`, `ENV`, `Flags` - `JSON` 内容支持注释,可以设置解析时清除注释 - 其他驱动都是按需使用,不使用的不会加载编译到应用中 - 支持多个文件、多数据加载 @@ -391,6 +391,7 @@ go test -cover ./... ## 相关包 - Ini 解析 [gookit/ini/parser](https://github.com/gookit/ini/tree/master/parser) +- Properties 解析 [gookit/properties](https://github.com/gookit/properties) - Yaml 解析 [go-yaml](https://github.com/go-yaml/yaml) - Toml 解析 [go toml](https://github.com/BurntSushi/toml) - 数据合并 [mergo](https://github.com/imdario/mergo) diff --git a/go.mod b/go.mod index 64fbfc1..eb87d76 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,9 @@ go 1.16 require ( github.com/BurntSushi/toml v1.2.0 - github.com/gookit/goutil v0.5.7 + github.com/gookit/goutil v0.5.9 github.com/gookit/ini/v2 v2.1.1 - github.com/gookit/properties v0.0.0-20220809153718-db6ef1a19b3e + github.com/gookit/properties v0.1.0 github.com/hashicorp/hcl v1.0.0 github.com/hashicorp/hcl/v2 v2.13.0 github.com/imdario/mergo v0.3.13 @@ -15,7 +15,6 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/stretchr/testify v1.8.0 github.com/yosuke-furukawa/json5 v0.1.1 - golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index d71c8bd..02f21cd 100644 --- a/go.sum +++ b/go.sum @@ -22,12 +22,12 @@ github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ= github.com/gookit/color v1.5.1/go.mod h1:wZFzea4X8qN6vHOSP2apMb4/+w/orMznEzYsIHPaqKM= github.com/gookit/goutil v0.5.3/go.mod h1:W0rVeVN9EcoRV+ODq91TXvqoUA87BXGi36WFVykCKRI= -github.com/gookit/goutil v0.5.7 h1:WaeQ96zRB/69ho5fOcOb1J2diRAMXX5i9Pm1z5Uh2v4= -github.com/gookit/goutil v0.5.7/go.mod h1:Cmt+ahuf18EHMAlF6EoOUD/KAdYcD7FdVUbpZC+zTfc= +github.com/gookit/goutil v0.5.9 h1:DBaSHaealbqxLWEZrEt/vqnPKiJHLQJau9dbcFQG/ng= +github.com/gookit/goutil v0.5.9/go.mod h1:iZLXpRhMqKGvKtJ9+b0cdls2gXRH4HaGWQfkf2mdHRQ= github.com/gookit/ini/v2 v2.1.1 h1:q2VtSSl/ivTOZMPvxhjWxO3f146NvWM84jBQZETj/1o= github.com/gookit/ini/v2 v2.1.1/go.mod h1:zkMTCrnE2QgDW0izB/pRtgEKKjXmT/22dfk5eZg+IHo= -github.com/gookit/properties v0.0.0-20220809153718-db6ef1a19b3e h1:DT+o0GuumXSZH3KIj7B/CMSPau+cgfGQHxkCeAk5LGo= -github.com/gookit/properties v0.0.0-20220809153718-db6ef1a19b3e/go.mod h1:Wktc5GebCZd7ZV9quELTa9syMBI3CiuRqimltpGo2Ww= +github.com/gookit/properties v0.1.0 h1:UHwgz0UCjxJ0q36qmvOAWNSdNh+yGIBUjUDaKzLryJY= +github.com/gookit/properties v0.1.0/go.mod h1:qg423zj2UMRsOilko6MAqyUBYQETTLjkk9NejTlMeBE= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc= @@ -43,8 +43,9 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM= github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= @@ -96,8 +97,8 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/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-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE= @@ -105,8 +106,9 @@ golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9sn golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +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= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= diff --git a/properties/properties_test.go b/properties/properties_test.go index 5f9343a..7f78756 100644 --- a/properties/properties_test.go +++ b/properties/properties_test.go @@ -19,13 +19,14 @@ func TestDriver(t *testing.T) { is.True(c.HasDecoder(properties.Name)) is.True(c.HasEncoder(properties.Name)) - // m := struct { - // N string - // }{} - // err := properties.Decoder([]byte(`{ - // // comments - // "n":"v"} - // `), &m) - // is.Nil(err) - // is.Eq("v", m.N) + m := struct { + N string + }{} + err := properties.Decoder([]byte(` +// comments +n=value + `), &m) + + is.Nil(err) + is.Eq("value", m.N) } From 46cb2f199d44d842a2bfc7a9d127a825286b778a Mon Sep 17 00:00:00 2001 From: Inhere Date: Mon, 22 Aug 2022 19:39:49 +0800 Subject: [PATCH 29/33] up: enhance the Set logic, allow change type of map item value. issues #70 --- issues_test.go | 79 ++++++++++++++++++++++++++++++++++---------------- write.go | 7 ++--- 2 files changed, 57 insertions(+), 29 deletions(-) diff --git a/issues_test.go b/issues_test.go index b311fec..e149350 100644 --- a/issues_test.go +++ b/issues_test.go @@ -11,7 +11,7 @@ import ( "github.com/gookit/goutil/dump" "github.com/gookit/goutil/fsutil" "github.com/gookit/goutil/testutil" - "github.com/stretchr/testify/assert" + "github.com/gookit/goutil/testutil/assert" ) // https://github.com/gookit/config/issues/37 @@ -30,7 +30,7 @@ func TestIssues_37(t *testing.T) { } } `) - is.NoError(err) + is.NoErr(err) dump.Println(c.Data()) is.Panics(func() { @@ -58,7 +58,7 @@ func TestIssues37_yaml_v3(t *testing.T) { } } `) - is.NoError(err) + is.NoErr(err) dump.Println(c.Data()) err = c.LoadStrings(config.Yaml, ` @@ -67,7 +67,7 @@ lang: allowed: en: "666" `) - is.NoError(err) + is.NoErr(err) dump.Println(c.Data()) } @@ -85,18 +85,18 @@ func TestIssues_46(t *testing.T) { } `) - is.NoError(err) + is.NoErr(err) dump.Println(c.Data()) val, _ := c.GetValue("http") mp := val.(map[string]interface{}) dump.Println(mp) - is.Equal("${HTTP_PORT|8080}", mp["port"]) + is.Eq("${HTTP_PORT|8080}", mp["port"]) smp := c.StringMap("http") dump.Println(smp) is.Contains(smp, "port") - is.Equal("8080", smp["port"]) + is.Eq("8080", smp["port"]) type Http struct { Port int @@ -104,16 +104,16 @@ func TestIssues_46(t *testing.T) { h := &Http{} err = c.BindStruct("http", h) - is.NoError(err) + is.NoErr(err) dump.Println(h) - is.Equal(8080, h.Port) + is.Eq(8080, h.Port) testutil.MockEnvValue("HTTP_PORT", "19090", func(_ string) { h := &Http{} err = c.BindStruct("http", h) - is.NoError(err) + is.NoErr(err) dump.Println(h) - is.Equal(19090, h.Port) + is.Eq(19090, h.Port) }) } @@ -125,19 +125,48 @@ func TestIssues_59(t *testing.T) { c.AddDriver(ini.Driver) err := c.LoadFiles("testdata/ini_base.ini") - is.NoError(err) + is.NoErr(err) dump.Println(c.Data()) dumpfile := "testdata/issues59.ini" out := fsutil.MustCreateFile(dumpfile, 0666, 0666) _, err = c.DumpTo(out, config.Ini) - is.NoError(err) + is.NoErr(err) str := string(fsutil.MustReadFile(dumpfile)) is.Contains(str, "name = app") is.Contains(str, "key1 = val1") } +// https://github.com/gookit/config/issues/70 +func TestIssues_70(t *testing.T) { + c := config.New("test") + + err := c.LoadStrings(config.JSON, `{ + "parent": { + "child": "Test Var" + } +}`) + + assert.NoErr(t, err) + assert.Eq(t, "Test Var", c.String("parent.child")) + dump.P(c.Data()) + + // cannot this. + err = c.Set("parent.child.grandChild", "New Val") + assert.Err(t, err) + + err = c.Set("parent.child", map[string]interface{}{ + "grandChild": "New Val", + }) + assert.NoErr(t, err) + assert.Eq(t, map[string]interface{}{ + "grandChild": "New Val", + }, c.Get("parent.child")) + + dump.P(c.Data()) +} + // https://github.com/gookit/config/issues/76 func TestIssues_76(t *testing.T) { is := assert.New(t) @@ -153,15 +182,15 @@ func TestIssues_76(t *testing.T) { "key0": 234 } `) - is.NoError(err) + is.NoErr(err) ss := c.Strings("key0") is.Empty(ss) lastErr := c.Error() - is.Error(lastErr) - is.Equal("value cannot be convert to []string, key is 'key0'", lastErr.Error()) - is.NoError(c.Error()) + is.Err(lastErr) + is.Eq("value cannot be convert to []string, key is 'key0'", lastErr.Error()) + is.NoErr(c.Error()) } // https://github.com/gookit/config/issues/81 @@ -179,7 +208,7 @@ func TestIssues_81(t *testing.T) { "idleTime": "1m" } `) - is.NoError(err) + is.NoErr(err) type Options struct { ConnTime time.Duration `json:"connTime"` @@ -189,14 +218,14 @@ func TestIssues_81(t *testing.T) { opt := &Options{} err = c.BindStruct("", opt) - is.NoError(err) - is.Equal("10s", c.String("connTime")) + is.NoErr(err) + is.Eq("10s", c.String("connTime")) wantTm, err := time.ParseDuration("10s") - is.NoError(err) - is.Equal(wantTm, opt.ConnTime) + is.NoErr(err) + is.Eq(wantTm, opt.ConnTime) - is.Equal("1m", c.String("idleTime")) + is.Eq("1m", c.String("idleTime")) wantTm, err = time.ParseDuration("1m") - is.NoError(err) - is.Equal(wantTm, opt.IdleTime) + is.NoErr(err) + is.Eq(wantTm, opt.IdleTime) } diff --git a/write.go b/write.go index 354067a..d70889b 100644 --- a/write.go +++ b/write.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/gookit/goutil/arrutil" + "github.com/gookit/goutil/maputil" "github.com/gookit/goutil/strutil" "github.com/imdario/mergo" ) @@ -90,10 +91,8 @@ func (c *Config) Set(key string, val interface{}, setByPath ...bool) (err error) c.data[topK] = dstItem case map[string]interface{}: // from json,toml,yaml.v3 - // create a new item for the topK - newItem := buildValueByPath(paths, val) - // merge new item to old item - if err = mergo.Merge(&typeData, &newItem, mergo.WithOverride); err != nil { + // enhanced: 'top.sub'=string, can set 'top.sub' to other type. eg: 'top.sub'=map + if err = maputil.SetByKeys(&typeData, paths, val); err != nil { return } From 808bb97157fb9fc7caca6450c76ca1038b913ed6 Mon Sep 17 00:00:00 2001 From: Inhere Date: Mon, 22 Aug 2022 19:40:38 +0800 Subject: [PATCH 30/33] up: update readme and examples, default recommend use yaml.v3 --- README.md | 4 ++-- README.zh-CN.md | 4 ++-- _examples/yaml.go | 6 +++--- config_test.go | 7 ++----- dotnev/dotenv.go | 21 +++------------------ dotnev/dotenv_test.go | 24 ------------------------ yaml/yaml.go | 2 +- 7 files changed, 13 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index e0e3e30..974aad5 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ package main import ( "github.com/gookit/config/v2" - "github.com/gookit/config/v2/yaml" + "github.com/gookit/config/v2/yamlv3" ) // go run ./examples/yaml.go @@ -84,7 +84,7 @@ func main() { config.WithOptions(config.ParseEnv) // add driver for support yaml content - config.AddDriver(yaml.Driver) + config.AddDriver(yamlv3.Driver) err := config.LoadFiles("testdata/yml_base.yml") if err != nil { diff --git a/README.zh-CN.md b/README.zh-CN.md index fc62984..94c0483 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -75,7 +75,7 @@ package main import ( "github.com/gookit/config/v2" - "github.com/gookit/config/v2/yaml" + "github.com/gookit/config/v2/yamlv3" ) // go run ./examples/yaml.go @@ -84,7 +84,7 @@ func main() { config.WithOptions(config.ParseEnv) // 添加驱动程序以支持yaml内容解析(除了JSON是默认支持,其他的则是按需使用) - config.AddDriver(yaml.Driver) + config.AddDriver(yamlv3.Driver) // 加载配置,可以同时传入多个文件 err := config.LoadFiles("testdata/yml_base.yml") diff --git a/_examples/yaml.go b/_examples/yaml.go index f9561c2..1f68bb1 100644 --- a/_examples/yaml.go +++ b/_examples/yaml.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/gookit/config/v2" - "github.com/gookit/config/v2/yaml" + "github.com/gookit/config/v2/yamlv3" ) // go run ./examples/yaml.go @@ -12,9 +12,9 @@ func main() { config.WithOptions(config.ParseEnv) // only add decoder - // config.SetDecoder(config.Yaml, yaml.Decoder) + // config.SetDecoder(config.Yaml, yamlv3.Decoder) // Or - config.AddDriver(yaml.Driver) + config.AddDriver(yamlv3.Driver) err := config.LoadFiles("testdata/yml_base.yml") if err != nil { diff --git a/config_test.go b/config_test.go index 55fdcb6..2b33a7b 100644 --- a/config_test.go +++ b/config_test.go @@ -34,15 +34,12 @@ var jsonStr = `{ func Example() { // WithOptions(ParseEnv) - // add Decoder and Encoder - // use yaml github.com/gookit/config/yaml - // AddDriver(Yaml, yaml.Driver) + // use yaml github.com/gookit/config/yamlv3 + // AddDriver(Yaml, yamlv3.Driver) // use toml github.com/gookit/config/toml // AddDriver(Toml, toml.Driver) // use toml github.com/gookit/config/hcl // AddDriver(Hcl, hcl.Driver) - // Or - // config.DecoderEncoder(config.JSON, yaml.Decoder, yaml.Encoder) err := LoadFiles("testdata/json_base.json") if err != nil { diff --git a/dotnev/dotenv.go b/dotnev/dotenv.go index 0a91787..fe51f56 100644 --- a/dotnev/dotenv.go +++ b/dotnev/dotenv.go @@ -7,23 +7,6 @@ import ( "github.com/gookit/ini/v2/dotenv" ) -var ( - // UpperEnvKey change key to upper on set ENV - UpperEnvKey = true - - // DefaultName default file name - DefaultName = ".env" - - // OnlyLoadExists load on file exists - OnlyLoadExists bool - - // save original Env data - // originalEnv []string - - // cache all loaded ENV data - // loadedData = map[string]string{} -) - // LoadedData get all loaded data by dontenv // Deprecated: please use github.com/gookit/ini/v2/dotenv func LoadedData() map[string]string { @@ -45,7 +28,9 @@ func DontUpperEnvKey() { // Load parse .env file data to os ENV. // // Usage: -// dotenv.Load("./", ".env") +// +// dotenv.Load("./", ".env") +// // Deprecated: please use github.com/gookit/ini/v2/dotenv func Load(dir string, filenames ...string) (err error) { return dotenv.Load(dir, filenames...) diff --git a/dotnev/dotenv_test.go b/dotnev/dotenv_test.go index 1f467fc..804e36d 100644 --- a/dotnev/dotenv_test.go +++ b/dotnev/dotenv_test.go @@ -88,27 +88,3 @@ func TestLoadFromMap(t *testing.T) { }) assert.Error(t, err) } - -func TestDontUpperEnvKey(t *testing.T) { - assert.Equal(t, "", os.Getenv("DONT_ENV_TEST")) - - DontUpperEnvKey() - - err := LoadFromMap(map[string]string{ - "dont_env_test": "val", - }) - - assert.Contains(t, fmt.Sprint(os.Environ()), "dont_env_test=val") - assert.NoError(t, err) - assert.Equal(t, "val", Get("dont_env_test")) - - // on windows, os.Getenv() not case sensitive - if runtime.GOOS == "windows" { - assert.Equal(t, "val", Get("DONT_ENV_TEST")) - } else { - assert.Equal(t, "", Get("DONT_ENV_TEST")) - } - - UpperEnvKey = true // revert - ClearLoaded() -} diff --git a/yaml/yaml.go b/yaml/yaml.go index 05be7a2..8d630a8 100644 --- a/yaml/yaml.go +++ b/yaml/yaml.go @@ -2,7 +2,6 @@ Package yaml is a driver use YAML format content as config source Usage please see example: - */ package yaml @@ -19,4 +18,5 @@ var Decoder config.Decoder = yaml.Unmarshal var Encoder config.Encoder = yaml.Marshal // Driver for yaml +// TIP: recommended use the yamlv3.Driver var Driver = config.NewDriver(config.Yaml, Decoder, Encoder) From 167f6196d674df6b4a26abc04afb010dfab99870 Mon Sep 17 00:00:00 2001 From: Inhere Date: Mon, 22 Aug 2022 21:45:50 +0800 Subject: [PATCH 31/33] chore: update some examples, update some for json driver --- TODO.md | 3 ++- _examples/yamlv2.go | 66 +++++++++++++++++++++++++++++++++++++++++++++ driver.go | 42 ++++++++++++++++++++--------- 3 files changed, 98 insertions(+), 13 deletions(-) create mode 100644 _examples/yamlv2.go diff --git a/TODO.md b/TODO.md index 9cbdba4..bf8d91d 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,5 @@ # TODO - remote `etcd` `consul` -- watch config files +- watch changed config files and reload +- set default value on binding struct. use tag `defalut` diff --git a/_examples/yamlv2.go b/_examples/yamlv2.go new file mode 100644 index 0000000..09fc742 --- /dev/null +++ b/_examples/yamlv2.go @@ -0,0 +1,66 @@ +package main + +import ( + "fmt" + + "github.com/gookit/config/v2" + "github.com/gookit/config/v2/yaml" +) + +// go run ./examples/yamlv2.go +func main() { + config.WithOptions(config.ParseEnv) + + // only add decoder + // config.SetDecoder(config.Yaml, yaml.Decoder) + // Or + config.AddDriver(yaml.Driver) + + err := config.LoadFiles("testdata/yml_base.yml") + if err != nil { + panic(err) + } + + fmt.Printf("config data: \n %#v\n", config.Data()) + + err = config.LoadFiles("testdata/yml_other.yml") + // config.LoadFiles("testdata/yml_base.yml", "testdata/yml_other.yml") + if err != nil { + panic(err) + } + + fmt.Printf("config data: \n %#v\n", config.Data()) + fmt.Print("get config example:\n") + + name := config.String("name") + fmt.Printf("- get string\n val: %v\n", name) + + arr1 := config.Strings("arr1") + fmt.Printf("- get array\n val: %#v\n", arr1) + + val0 := config.String("arr1.0") + fmt.Printf("- get sub-value by path 'arr.index'\n val: %#v\n", val0) + + map1 := config.StringMap("map1") + fmt.Printf("- get map\n val: %#v\n", map1) + + val0 = config.String("map1.key") + fmt.Printf("- get sub-value by path 'map.key'\n val: %#v\n", val0) + + // can parse env name(ParseEnv: true) + fmt.Printf("get env 'envKey' val: %s\n", config.String("envKey", "")) + fmt.Printf("get env 'envKey1' val: %s\n", config.String("envKey1", "")) + + // set value + config.Set("name", "new name") + name = config.String("name") + fmt.Printf("- set string\n val: %v\n", name) + + // if you want export config data + // buf := new(bytes.Buffer) + // _, err = config.DumpTo(buf, config.Yaml) + // if err != nil { + // panic(err) + // } + // fmt.Printf("export config:\n%s", buf.String()) +} diff --git a/driver.go b/driver.go index 270d0cb..ee8e810 100644 --- a/driver.go +++ b/driver.go @@ -58,6 +58,10 @@ func (d *StdDriver) GetEncoder() Encoder { return d.encoder } +/************************************************************* + * json driver + *************************************************************/ + var ( // JSONAllowComments support write comments on json file. JSONAllowComments = true @@ -68,24 +72,21 @@ var ( // JSONDecoder for json decode var JSONDecoder Decoder = func(data []byte, v interface{}) (err error) { - if JSONAllowComments { - str := jsonutil.StripComments(string(data)) - return json.Unmarshal([]byte(str), v) - } - - return json.Unmarshal(data, v) + JSONDriver.ClearComments = JSONAllowComments + return JSONDriver.Decode(data, v) } // JSONEncoder for json encode var JSONEncoder Encoder = func(v interface{}) (out []byte, err error) { - if len(JSONMarshalIndent) > 0 { - return json.MarshalIndent(v, "", JSONMarshalIndent) - } - return json.Marshal(v) + JSONDriver.MarshalIndent = JSONMarshalIndent + return JSONDriver.Encode(v) } // JSONDriver instance fot json var JSONDriver = &jsonDriver{ + ClearComments: JSONAllowComments, + MarshalIndent: JSONMarshalIndent, + // inject StdDriver: StdDriver{ name: JSON, decoder: JSONDecoder, @@ -107,12 +108,29 @@ func (d *jsonDriver) Name() string { return d.name } +// Decode for the driver +func (d *jsonDriver) Decode(data []byte, v interface{}) error { + if d.ClearComments { + str := jsonutil.StripComments(string(data)) + return json.Unmarshal([]byte(str), v) + } + return json.Unmarshal(data, v) +} + // GetDecoder for the driver func (d *jsonDriver) GetDecoder() Decoder { - return JSONDecoder + return d.Decode +} + +// Encode for the driver +func (d *jsonDriver) Encode(v interface{}) (out []byte, err error) { + if len(d.MarshalIndent) > 0 { + return json.MarshalIndent(v, "", JSONMarshalIndent) + } + return json.Marshal(v) } // GetEncoder for the driver func (d *jsonDriver) GetEncoder() Encoder { - return JSONEncoder + return d.Encode } From b71d0460289d014768d069402678445b63eefc45 Mon Sep 17 00:00:00 2001 From: Inhere Date: Mon, 22 Aug 2022 23:40:40 +0800 Subject: [PATCH 32/33] fix build error for built in json driver --- config_test.go | 6 ++++++ driver.go | 17 ++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/config_test.go b/config_test.go index 2b33a7b..1af452d 100644 --- a/config_test.go +++ b/config_test.go @@ -397,6 +397,12 @@ func TestJSONAllowComments(t *testing.T) { `), &m) is.Error(err) + JSONAllowComments = true + err = JSONDecoder([]byte(`{ +// comments +"n":"v"} +`), &m) + is.NoError(err) JSONAllowComments = old } diff --git a/driver.go b/driver.go index ee8e810..3e88059 100644 --- a/driver.go +++ b/driver.go @@ -64,9 +64,13 @@ func (d *StdDriver) GetEncoder() Encoder { var ( // JSONAllowComments support write comments on json file. + // + // Deprecated: please use JSONDriver.ClearComments = true JSONAllowComments = true // JSONMarshalIndent if not empty, will use json.MarshalIndent for encode data. + // + // Deprecated: please use JSONDriver.MarshalIndent JSONMarshalIndent string ) @@ -84,19 +88,14 @@ var JSONEncoder Encoder = func(v interface{}) (out []byte, err error) { // JSONDriver instance fot json var JSONDriver = &jsonDriver{ + driverName: JSON, ClearComments: JSONAllowComments, MarshalIndent: JSONMarshalIndent, - // inject - StdDriver: StdDriver{ - name: JSON, - decoder: JSONDecoder, - encoder: JSONEncoder, - }, } // jsonDriver for json format content type jsonDriver struct { - StdDriver + driverName string // ClearComments before parse JSON string. ClearComments bool // MarshalIndent if not empty, will use json.MarshalIndent for encode data. @@ -105,7 +104,7 @@ type jsonDriver struct { // Name of the driver func (d *jsonDriver) Name() string { - return d.name + return d.driverName } // Decode for the driver @@ -125,7 +124,7 @@ func (d *jsonDriver) GetDecoder() Decoder { // Encode for the driver func (d *jsonDriver) Encode(v interface{}) (out []byte, err error) { if len(d.MarshalIndent) > 0 { - return json.MarshalIndent(v, "", JSONMarshalIndent) + return json.MarshalIndent(v, "", d.MarshalIndent) } return json.Marshal(v) } From 752b6e9891f8e88c3807c8dde71c8aec198c6a44 Mon Sep 17 00:00:00 2001 From: Inhere Date: Mon, 22 Aug 2022 23:52:50 +0800 Subject: [PATCH 33/33] chore: update readme, add test on go1.19 and rm go1.15 --- .github/workflows/go.yml | 2 +- README.md | 2 +- README.zh-CN.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 804f4fd..99b997e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go_version: [1.15, 1.16, 1.17, 1.18] + go_version: [1.16, 1.17, 1.18, 1.19] steps: - name: Check out code diff --git a/README.md b/README.md index 974aad5..7c6f0f6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Config ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/gookit/config?style=flat-square) -[![Codacy Badge](https://api.codacy.com/project/badge/Grade/d6ac163ee63649ec92c1566e42f09c11)](https://app.codacy.com/app/inhere/config) +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/1e0f0ca096d94ffdab375234ec4167ee)](https://app.codacy.com/gh/gookit/config?utm_source=github.com&utm_medium=referral&utm_content=gookit/config&utm_campaign=Badge_Grade_Settings) [![GoDoc](https://godoc.org/github.com/gookit/config?status.svg)](https://pkg.go.dev/github.com/gookit/config) [![Build Status](https://travis-ci.org/gookit/config.svg?branch=master)](https://travis-ci.org/gookit/config) [![Actions Status](https://github.com/gookit/config/workflows/Unit-Tests/badge.svg)](https://github.com/gookit/config/actions) diff --git a/README.zh-CN.md b/README.zh-CN.md index 94c0483..e002212 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -1,7 +1,7 @@ # Config ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/gookit/config?style=flat-square) -[![Codacy Badge](https://api.codacy.com/project/badge/Grade/d6ac163ee63649ec92c1566e42f09c11)](https://app.codacy.com/app/inhere/config) +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/1e0f0ca096d94ffdab375234ec4167ee)](https://app.codacy.com/gh/gookit/config?utm_source=github.com&utm_medium=referral&utm_content=gookit/config&utm_campaign=Badge_Grade_Settings) [![GoDoc](https://godoc.org/github.com/gookit/config?status.svg)](https://godoc.org/github.com/gookit/config) [![Build Status](https://travis-ci.org/gookit/config.svg?branch=master)](https://travis-ci.org/gookit/config) [![Actions Status](https://github.com/gookit/config/workflows/Unit-Tests/badge.svg)](https://github.com/gookit/config/actions)