Skip to content

Commit 552e649

Browse files
committed
[data/binding] .NewUntypedMap() returns UntypedMap again
This introduces an un-exported constructor to avoid type assertions or construction duplication.
1 parent 933cb77 commit 552e649

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

data/binding/maps.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ type UntypedMap interface {
3939
// NewUntypedMap creates a new, empty map binding of string to any.
4040
//
4141
// Since: 2.0
42-
func NewUntypedMap() ExternalUntypedMap {
43-
return &mapBase{items: make(map[string]reflectUntyped), val: &map[string]any{}}
42+
func NewUntypedMap() UntypedMap {
43+
return newExternalUntypedMap()
4444
}
4545

4646
// BindUntypedMap creates a new map binding of string to any based on the data passed.
@@ -49,7 +49,7 @@ func NewUntypedMap() ExternalUntypedMap {
4949
// Since: 2.0
5050
func BindUntypedMap(d *map[string]any) ExternalUntypedMap {
5151
if d == nil {
52-
return NewUntypedMap()
52+
return newExternalUntypedMap()
5353
}
5454
m := &mapBase{items: make(map[string]reflectUntyped), val: d, updateExternal: true}
5555

@@ -77,7 +77,7 @@ type Struct interface {
7777
// Since: 2.0
7878
func BindStruct(i any) Struct {
7979
if i == nil {
80-
return NewUntypedMap()
80+
return newExternalUntypedMap()
8181
}
8282
t := reflect.TypeOf(i)
8383
if t.Kind() != reflect.Pointer ||
@@ -107,6 +107,10 @@ func BindStruct(i any) Struct {
107107
return s
108108
}
109109

110+
func newExternalUntypedMap() ExternalUntypedMap {
111+
return &mapBase{items: make(map[string]reflectUntyped), val: &map[string]any{}}
112+
}
113+
110114
type reflectUntyped interface {
111115
DataItem
112116
get() (any, error)

0 commit comments

Comments
 (0)