Skip to content

Commit 6d75064

Browse files
uroshercogrs
authored andcommitted
resolve resource constructor function shadowing builtin new function (#190)
1 parent 798b505 commit 6d75064

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

resource/index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func NewIndex() Index {
4848
// Bind a resource at the specified endpoint name.
4949
func (i *index) Bind(name string, s schema.Schema, h Storer, c Conf) *Resource {
5050
assertNotBound(name, i.resources, nil)
51-
sr := new(name, s, h, c)
51+
sr := newResource(name, s, h, c)
5252
i.resources.add(sr)
5353
return sr
5454
}

resource/resource.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ func (v validatorFallback) GetField(name string) *schema.Field {
6767
return v.fallback.GetField(name)
6868
}
6969

70-
// new creates a new resource with provided spec, handler and config.
71-
func new(name string, s schema.Schema, h Storer, c Conf) *Resource {
70+
// newResource creates a new resource with provided spec, handler and config.
71+
func newResource(name string, s schema.Schema, h Storer, c Conf) *Resource {
7272
return &Resource{
7373
name: name,
7474
path: name,
@@ -136,7 +136,7 @@ func (r *Resource) Bind(name, field string, s schema.Schema, h Storer, c Conf) *
136136
if f := s.GetField(field); f == nil {
137137
logPanicf(nil, "Cannot bind `%s' as sub-resource: field `%s' does not exist in the sub-resource'", name, field)
138138
}
139-
sr := new(name, s, h, c)
139+
sr := newResource(name, s, h, c)
140140
sr.parentField = field
141141
sr.path = r.path + "." + name
142142
r.resources.add(sr)

resource/resource_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func TestSubResources(t *testing.T) {
9797
}
9898

9999
func TestResourceBindDupViaAlias(t *testing.T) {
100-
r := new("name", schema.Schema{Fields: schema.Fields{"f": {}}}, nil, DefaultConf)
100+
r := newResource("name", schema.Schema{Fields: schema.Fields{"f": {}}}, nil, DefaultConf)
101101
r.Alias("foo", url.Values{})
102102
log.SetOutput(ioutil.Discard)
103103
assert.Panics(t, func() {
@@ -106,7 +106,7 @@ func TestResourceBindDupViaAlias(t *testing.T) {
106106
}
107107

108108
func TestResourceBindOnMissingField(t *testing.T) {
109-
r := new("name", schema.Schema{Fields: schema.Fields{"f": {}}}, nil, DefaultConf)
109+
r := newResource("name", schema.Schema{Fields: schema.Fields{"f": {}}}, nil, DefaultConf)
110110
log.SetOutput(ioutil.Discard)
111111
assert.Panics(t, func() {
112112
r.Bind("foo", "m", schema.Schema{Fields: schema.Fields{"f": {}}}, nil, DefaultConf)

0 commit comments

Comments
 (0)