Skip to content

Commit 6488ba2

Browse files
authored
Merge pull request #14 from lvan100/main
Replace spring-core/util/assert with lvan100/go-assert
2 parents c051255 + d7b1a34 commit 6488ba2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+198
-1214
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ go.work.sum
3030
# IDE files
3131
.idea/
3232

33-
/conf/remote/app-online.properties
33+
/conf/remote/
3434

3535
gs/examples/bookman/conf/
3636
gs/examples/bookman/log/*.log

conf/bind_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"time"
2727

2828
"github.com/go-spring/spring-core/conf"
29-
"github.com/go-spring/spring-core/util/assert"
29+
"github.com/lvan100/go-assert"
3030
"github.com/spf13/cast"
3131
)
3232

conf/conf_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"testing"
2323

2424
"github.com/go-spring/spring-core/conf"
25-
"github.com/go-spring/spring-core/util/assert"
25+
"github.com/lvan100/go-assert"
2626
)
2727

2828
func TestProperties_Load(t *testing.T) {

conf/expr_test.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"testing"
2121

2222
"github.com/go-spring/spring-core/conf"
23-
"github.com/go-spring/spring-core/util/assert"
23+
"github.com/lvan100/go-assert"
2424
)
2525

2626
func TestExpr(t *testing.T) {
@@ -51,17 +51,6 @@ func TestExpr(t *testing.T) {
5151
assert.Error(t, err, "validate failed on .* for value 14")
5252
})
5353

54-
t.Run("syntax error", func(t *testing.T) {
55-
var v struct {
56-
A int `value:"${a}" expr:"checkInt($2)"`
57-
}
58-
p := conf.Map(map[string]interface{}{
59-
"a": 4,
60-
})
61-
err := p.Bind(&v)
62-
assert.Error(t, err, "eval .* returns error")
63-
})
64-
6554
t.Run("return not bool", func(t *testing.T) {
6655
var v struct {
6756
A int `value:"${a}" expr:"$+$"`

conf/reader/json/json_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package json
1919
import (
2020
"testing"
2121

22-
"github.com/go-spring/spring-core/util/assert"
22+
"github.com/lvan100/go-assert"
2323
)
2424

2525
func TestRead(t *testing.T) {

conf/reader/prop/prop_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package prop
1919
import (
2020
"testing"
2121

22-
"github.com/go-spring/spring-core/util/assert"
22+
"github.com/lvan100/go-assert"
2323
)
2424

2525
func TestRead(t *testing.T) {
@@ -46,7 +46,7 @@ func TestRead(t *testing.T) {
4646
})
4747
})
4848

49-
t.Run("map", func(t *testing.T) {
49+
t.Run("simple map", func(t *testing.T) {
5050
r, err := Read([]byte(`
5151
map.bool=false
5252
map.int=3
@@ -62,7 +62,7 @@ func TestRead(t *testing.T) {
6262
})
6363
})
6464

65-
t.Run("array struct", func(t *testing.T) {
65+
t.Run("array with struct", func(t *testing.T) {
6666
r, err := Read([]byte(`
6767
array[0].bool=false
6868
array[0].int=3
@@ -86,7 +86,7 @@ func TestRead(t *testing.T) {
8686
})
8787
})
8888

89-
t.Run("map struct", func(t *testing.T) {
89+
t.Run("map with struct", func(t *testing.T) {
9090

9191
r, err := Read([]byte(`
9292
map.k1.bool=false

conf/reader/toml/toml_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package toml
1919
import (
2020
"testing"
2121

22-
"github.com/go-spring/spring-core/util/assert"
22+
"github.com/lvan100/go-assert"
2323
)
2424

2525
func TestRead(t *testing.T) {
@@ -53,7 +53,7 @@ func TestRead(t *testing.T) {
5353
})
5454
})
5555

56-
t.Run("map", func(t *testing.T) {
56+
t.Run("simple map", func(t *testing.T) {
5757
r, err := Read([]byte(`
5858
[map]
5959
bool=false
@@ -72,7 +72,7 @@ func TestRead(t *testing.T) {
7272
})
7373
})
7474

75-
t.Run("array struct", func(t *testing.T) {
75+
t.Run("array with struct", func(t *testing.T) {
7676
r, err := Read([]byte(`
7777
[[array]]
7878
bool=false
@@ -105,7 +105,7 @@ func TestRead(t *testing.T) {
105105
})
106106
})
107107

108-
t.Run("map struct", func(t *testing.T) {
108+
t.Run("map with struct", func(t *testing.T) {
109109
r, err := Read([]byte(`
110110
[map.k1]
111111
bool=false

conf/reader/yaml/yaml_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"strings"
2121
"testing"
2222

23-
"github.com/go-spring/spring-core/util/assert"
23+
"github.com/lvan100/go-assert"
2424
)
2525

2626
func TestRead(t *testing.T) {
@@ -56,7 +56,7 @@ func TestRead(t *testing.T) {
5656
})
5757
})
5858

59-
t.Run("map", func(t *testing.T) {
59+
t.Run("simple map", func(t *testing.T) {
6060
str := `
6161
map:
6262
bool: false
@@ -77,7 +77,7 @@ func TestRead(t *testing.T) {
7777
})
7878
})
7979

80-
t.Run("array struct", func(t *testing.T) {
80+
t.Run("array with struct", func(t *testing.T) {
8181
str := `
8282
array:
8383
-
@@ -112,7 +112,7 @@ func TestRead(t *testing.T) {
112112
})
113113
})
114114

115-
t.Run("map struct", func(t *testing.T) {
115+
t.Run("map with struct", func(t *testing.T) {
116116
str := `
117117
map:
118118
k1:

conf/storage/path_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"fmt"
2222
"testing"
2323

24-
"github.com/go-spring/spring-core/util/assert"
24+
"github.com/lvan100/go-assert"
2525
)
2626

2727
func TestSplitPath(t *testing.T) {

conf/storage/store.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,27 @@
1414
* limitations under the License.
1515
*/
1616

17-
// Package storage provides structured configuration storage, and `ConfigPath` represents
18-
// the hierarchical path of a configuration item.
19-
//
20-
// Each configuration item must have a well-defined type. The key of a configuration item
21-
// (its `path`) can be split into components that form a tree structure, where each node
22-
// corresponds to a part of the configuration hierarchy.
23-
//
24-
// The `path` serves both as the unique identifier (key) of the configuration item and
25-
// as its location within the configuration tree. This design mirrors the structure of
26-
// typical configuration file formats such as JSON, YAML, and TOML.
27-
//
28-
// A `path` is composed of only two types of elements:
29-
// - Key: Represents a map key in the configuration tree.
30-
// - Index: Represents an array index in the configuration tree.
31-
//
32-
// This approach ensures consistency, type safety, and compatibility with structured
33-
// configuration formats.
17+
/*
18+
Package storage provides hierarchical configuration storage and path parsing utilities.
19+
20+
Features:
21+
- Storage manages key-value pairs with support for nested paths, subkey lookup, and conflict detection.
22+
- Path represents structured access paths with support for parsing (SplitPath) and construction (JoinPath).
23+
- Supports two path types:
24+
- Key (e.g., "user.name") for map access
25+
- Index (e.g., "[0]") for array access
26+
27+
- Maintains a tree structure (treeNode) for consistent and type-safe hierarchy management.
28+
29+
Use cases:
30+
- Accessing values in JSON/YAML/TOML-like configs
31+
- Managing nested config data (CRUD)
32+
- Validating structure and detecting conflicts
33+
34+
Notes:
35+
- Path syntax follows common config patterns (e.g., "users[0].profile.age")
36+
- Type-safe path handling (keys vs. indices)
37+
*/
3438
package storage
3539

3640
import (

0 commit comments

Comments
 (0)