如何添加新路由来自动生成资源?

How to add new route to autogenerate resources?

请帮助我,我想添加新的 route/func 来生成资源(等用户)。

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

我找到了 func addRoute,但没有用。

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

我的想法是这样的。

"/users/handleSomething/idOfUser"

现在我只有这个功能:

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

感谢您的宝贵时间和帮助:)

PS:对不起我的英语:(

如果您需要其他路由,可以使用在 *App 类型上定义的方法 GET,POST,PUT, ...。 (https://gobuffalo.io/en/docs/routing#supported-http-methods)

要处理路由中的动态路径段,您可以使用命名参数。 (https://gobuffalo.io/en/docs/routing#named-parameters)

示例:

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

要检索命名参数的值,您可以使用 c.Param("id"),其中 c 是传递给处理程序的 buffalo 上下文。