简体   繁体   English

如何添加新路线以自动生成资源?

[英]How to add new route to autogenerate resources?

please help me, I want add new route/func to generate resource (etc. users). 请帮助我,我想添加新的路由/功能来生成资源(等用户)。

app.Resource("/users", UsersResource{})

I found func addRoute, but doesn't work. 我找到了func addRoute,但是不起作用。

func (a *App) addRoute(method string, url string, h Handler) *RouteInfo { ...

My idea is something like this. 我的想法是这样的。

"/users/handleSomething/idOfUser"

Right now i have only this func: 现在我只有这个功能:

List(Context)
Show(Context)
New(Context)
Create(Context)
Edit(Context)
Update(Context)
Destroy(Context)

Thx for your time and help :) 感谢您的时间和帮助:)

PS: Sorry for my English :( PS:对不起,我的英语:(

If you want additional routes you can use the methods GET,POST,PUT, ... that are defined on the *App type. 如果需要其他路由,可以使用*App类型上定义的GET,POST,PUT, ...方法。 ( https://gobuffalo.io/en/docs/routing#supported-http-methods ) https://gobuffalo.io/en/docs/routing#supported-http-methods

To handle dynamic path segments in the route you can use named parameters. 要处理路径中的动态路径段,可以使用命名参数。 ( https://gobuffalo.io/en/docs/routing#named-parameters ) https://gobuffalo.io/en/docs/routing#named-parameters

Example: 例:

app.PATCH("/users/handleSomething/{id}", handleSomethingHandler)

To retrieve the value of the named parameter you can use c.Param("id") where c is the buffalo context passed in to your handler. 要检索命名参数的值,可以使用c.Param("id") ,其中c是传递到处理程序中的buffalo上下文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM