go-aah / aah

A secure, flexible, rapid Go web framework
https://aahframework.org
MIT License
690 stars 33 forks source link

Methods are not discovered and not registered from controller struct properly #248

Closed adrianlop closed 5 years ago

adrianlop commented 5 years ago

What version of aah are you using (aah --version)?

aah v0.12.2 cli v0.13.3 go v1.11.5

Does this issue reproduce with the latest release?

yes

What operating system are you using (such as macOS, Linux and Windows)?

MacOS X

What did you do?

aah build

What did you expect to see?

successful build + being able to implement several methods for the same controller struct on several files.

What did you see instead?

ERROR AST: Method 'TriggerPrometheusCall' has incorrect struct recevier 'Controller' on file [/xxx/ops-api/app/controllers/oncaller/prometheus_webhook.go] at line #15

Additional context

If I create an additional struct like I showed you @jeevatkm then the build doesn't throw any error.

jeevatkm commented 5 years ago

@adrianlop Found the root issue why it was unable discover the method from controller struct.

I have reviewed you code and also aah AST flow. When Package files gets processed by aah AST code. There are no guaranteed order in the file processing for type & method since its type map[string]*File.

https://github.com/go-aah/aah/blob/8c41d00bc5289cdfb0f97b0023eefa24ee754172/ainsp/program.go#L90-L104

So as per your code, controller defined oncaller.go and action methods are defined all three files. Following log lines from random execution on my machine would convey what I mean.

2019-02-06 22:08:01.329 ERROR AST: Method 'TriggerGrafanaCall' has incorrect struct recevier 'Controller' on file [/xxx/ops-api/app/controllers/oncaller/grafana_webhook.go] at line #12
2019-02-06 22:08:01.329 ERROR AST: Method 'TriggerPrometheusCall' has incorrect struct recevier 'Controller' on file [/xxx/ops-api/app/controllers/oncaller/prometheus_webhook.go] at line #15
2019-02-06 22:08:11.154 ERROR AST: Method 'TriggerPrometheusCall' has incorrect struct recevier 'Controller' on file [/xxx/ops-api/app/controllers/oncaller/prometheus_webhook.go] at line #15

So solution to address this issue is to process all types for the package first and then go for processing methods.

jeevatkm commented 5 years ago

I have made a release of aah v0.12.3 && cli v0.13.4.

adrianlop commented 5 years ago

just updated the framework and the cli. it's working :) great stuff @jeevatkm, thank you very much for fixing this!