iris icon indicating copy to clipboard operation
iris copied to clipboard

How to customize the / segmentation rules of the controller? Or implement annotation routing

Open aadog opened this issue 2 years ago • 11 comments

How to customize the / segmentation rules of the controller? Or implement annotation routing

It seems that the initial MVC routing is not what you want most of the time, because many times it is a path composed of several words. For example, getUserInfo mostly just wants to generate / userinfo

In most cases, live template is used to generate code, so writing in another function requires a lot of work. Can we customize this rule or have annotations to generate routes

aadog avatar Mar 12 '22 14:03 aadog

Hello @a97077088,

Of course, you can customize the HTTP request controller's method through BeforeActivation controller's method. Example at: https://github.com/kataras/iris/blob/9cf6f9fa5ed0f3cff1d4504e7b631782bfde8ee1/_examples/mvc/basic/main.go#L92

https://github.com/kataras/iris/blob/9cf6f9fa5ed0f3cff1d4504e7b631782bfde8ee1/_examples/mvc/basic/main.go#L110

About method annotations, there is no such feature in Go programming language, you'll need a generator (a second executable tool that runs on the source code of your project) for that.

kataras avatar Mar 12 '22 19:03 kataras

BeforeActivation does not seem to be available under the live template, because the live template cannot control the existing code in most cases. Is there a way to customize this generation rule? Or implement the same annotation routing as beego using reflection

aadog avatar Mar 13 '22 02:03 aadog

Nice to hear from you, god of web frameworks

aadog avatar Mar 13 '22 02:03 aadog

does not seem to be available under the live template, because the live template cannot control the existing code in most cases.

Hello @a97077088. I didn't get it, what "live template" are you reffering to? Thanks

Or implement the same annotation routing as beego using reflection

Annotation is not a feature available in Go Programming Language with reflection. You need a code generator (2nd tool, see my previous answer).

kataras avatar Mar 13 '22 02:03 kataras

Live template is a fast code generation method provided by Goland ide

aadog avatar Mar 13 '22 06:03 aadog

image image

aadog avatar Mar 13 '22 06:03 aadog

It can generate code quickly. I preset some crud instructions, but it seems that path has encountered a big problem. The problem is that the uppercase letter of iris is divided into / directory

aadog avatar Mar 13 '22 06:03 aadog

Do you have a real-time chat tool? I can show you

aadog avatar Mar 13 '22 06:03 aadog

Live template is a fast code generation method provided by Goland ide

I've never used Goland IDE, I am VS Code fan from its first steps. But if you have experience with that feature of Goland IDE, we can work together to support the code generation you need.

but it seems that path has encountered a big problem. The problem is that the uppercase letter of iris is divided into / directory

I've already posted how to customize your paths and disable that auto-method binding to paths. This is not a problem.

Do you have a real-time chat tool? I can show you

Yes of course we do, you can contact me directly at https://chat.iris-go.com.

kataras avatar Mar 13 '22 16:03 kataras

@Kataras, thank you for your guidance. I will write a route generator based on ast analysis for iris after my recent work

aadog avatar Mar 16 '22 04:03 aadog

I'm excited to see that @aadog, don't hesitate to ping me for help!

kataras avatar Mar 25 '22 18:03 kataras