Skip to content

Commit

Permalink
resolve resource constructor function shadowing builtin new function (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
uroshercog authored and rs committed Jun 11, 2018
1 parent 798b505 commit 6d75064
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion resource/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewIndex() Index {
// Bind a resource at the specified endpoint name.
func (i *index) Bind(name string, s schema.Schema, h Storer, c Conf) *Resource {
assertNotBound(name, i.resources, nil)
sr := new(name, s, h, c)
sr := newResource(name, s, h, c)
i.resources.add(sr)
return sr
}
Expand Down
6 changes: 3 additions & 3 deletions resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func (v validatorFallback) GetField(name string) *schema.Field {
return v.fallback.GetField(name)
}

// new creates a new resource with provided spec, handler and config.
func new(name string, s schema.Schema, h Storer, c Conf) *Resource {
// newResource creates a new resource with provided spec, handler and config.
func newResource(name string, s schema.Schema, h Storer, c Conf) *Resource {
return &Resource{
name: name,
path: name,
Expand Down Expand Up @@ -136,7 +136,7 @@ func (r *Resource) Bind(name, field string, s schema.Schema, h Storer, c Conf) *
if f := s.GetField(field); f == nil {
logPanicf(nil, "Cannot bind `%s' as sub-resource: field `%s' does not exist in the sub-resource'", name, field)
}
sr := new(name, s, h, c)
sr := newResource(name, s, h, c)
sr.parentField = field
sr.path = r.path + "." + name
r.resources.add(sr)
Expand Down
4 changes: 2 additions & 2 deletions resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestSubResources(t *testing.T) {
}

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

func TestResourceBindOnMissingField(t *testing.T) {
r := new("name", schema.Schema{Fields: schema.Fields{"f": {}}}, nil, DefaultConf)
r := newResource("name", schema.Schema{Fields: schema.Fields{"f": {}}}, nil, DefaultConf)
log.SetOutput(ioutil.Discard)
assert.Panics(t, func() {
r.Bind("foo", "m", schema.Schema{Fields: schema.Fields{"f": {}}}, nil, DefaultConf)
Expand Down

0 comments on commit 6d75064

Please sign in to comment.