Repository: goadesign/goa (go)
Issue: cannot use resource method name "Use"
if I use following method name I get an error.

in resources.go:

Method("use", func() {
		Description("sample description")
		.. 
   ..
..

error when building the go project:

gen/test/endpoints.go:50:6: type Endpoints has both field and method named Use
Pull request description: Properly handle services with method named 'Use'
Fix #2161

Patch:
diff --git a/codegen/service/service_data.go b/codegen/service/service_data.go
index c4409fac..94bb33aa 100644
--- a/codegen/service/service_data.go
+++ b/codegen/service/service_data.go
@@ -473,6 +473,7 @@ func (d ServicesData) analyze(service *expr.ServiceExpr) *Data {
 	)
 	{
 		scope = codegen.NewNameScope()
+		scope.Unique("Use") // Reserve "Use" for Endpoints struct Use method.
 		viewScope = codegen.NewNameScope()
 		pkgName = scope.HashedUnique(service, strings.ToLower(codegen.Goify(service.Name, false)), "svc")
 		viewspkg = pkgName + "views"
@@ -709,7 +710,7 @@ func buildMethodData(m *expr.MethodExpr, svcPkgName string, service *expr.Servic
 		svrStream    *StreamData
 		cliStream    *StreamData
 	)
-	vname = codegen.Goify(m.Name, true)
+	vname = scope.Unique(codegen.Goify(m.Name, true), "Endpoint")
 	desc = m.Description
 	if desc == "" {
 		desc = codegen.Goify(m.Name, true) + " implements " + m.Name + "."


Test patch:
diff --git a/codegen/service/endpoint_test.go b/codegen/service/endpoint_test.go
index 581d94a3..3c3bff6b 100644
--- a/codegen/service/endpoint_test.go
+++ b/codegen/service/endpoint_test.go
@@ -18,6 +18,7 @@ func TestEndpoint(t *testing.T) {
 		Code string
 	}{
 		{"single", testdata.SingleEndpointDSL, testdata.SingleEndpoint},
+		{"use", testdata.UseEndpointDSL, testdata.UseEndpoint},
 		{"multiple", testdata.MultipleEndpointsDSL, testdata.MultipleEndpoints},
 		{"no-payload", testdata.NoPayloadEndpointDSL, testdata.NoPayloadEndpoint},
 		{"with-result", testdata.WithResultEndpointDSL, testdata.WithResultEndpoint},
diff --git a/codegen/service/testdata/endpoint_code.go b/codegen/service/testdata/endpoint_code.go
index a54b6398..8de23499 100644
--- a/codegen/service/testdata/endpoint_code.go
+++ b/codegen/service/testdata/endpoint_code.go
@@ -29,6 +29,33 @@ func NewAEndpoint(s Service) goa.Endpoint {
 }
 `
 
+const UseEndpoint = `// Endpoints wraps the "UseEndpoint" service endpoints.
+type Endpoints struct {
+	UseEndpoint goa.Endpoint
+}
+
+// NewEndpoints wraps the methods of the "UseEndpoint" service with endpoints.
+func NewEndpoints(s Service) *Endpoints {
+	return &Endpoints{
+		UseEndpoint: NewUseEndpointEndpoint(s),
+	}
+}
+
+// Use applies the given middleware to all the "UseEndpoint" service endpoints.
+func (e *Endpoints) Use(m func(goa.Endpoint) goa.Endpoint) {
+	e.UseEndpoint = m(e.UseEndpoint)
+}
+
+// NewUseEndpointEndpoint returns an endpoint function that calls the method
+// "Use" of service "UseEndpoint".
+func NewUseEndpointEndpoint(s Service) goa.Endpoint {
+	return func(ctx context.Context, req interface{}) (interface{}, error) {
+		p := req.(string)
+		return nil, s.UseEndpoint(ctx, p)
+	}
+}
+`
+
 const MultipleEndpoints = `// Endpoints wraps the "MultipleEndpoints" service endpoints.
 type Endpoints struct {
 	B goa.Endpoint
diff --git a/codegen/service/testdata/endpoint_dsls.go b/codegen/service/testdata/endpoint_dsls.go
index 6ffd0c00..d6a11320 100644
--- a/codegen/service/testdata/endpoint_dsls.go
+++ b/codegen/service/testdata/endpoint_dsls.go
@@ -15,6 +15,14 @@ var SingleEndpointDSL = func() {
 	})
 }
 
+var UseEndpointDSL = func() {
+	Service("UseEndpoint", func() {
+		Method("Use", func() {
+			Payload(String)
+		})
+	})
+}
+
 var MultipleEndpointsDSL = func() {
 	var BType = Type("BType", func() {
 		Attribute("b", String)