You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the neat things Rocket.rs does is use function attributes to both declare the route that will bind to a function and specify the variables within a route. See an example of that here: https://rocket.rs/v0.4/guide/requests/#dynamic-paths
This is unfortunately not possible to carbon-copy due to Go's simplicity and minimalism. Also, routing/multiplexing isn't the goal of this library because there are plenty of great libraries for these tasks out there already!
I can however imagine building integrations for popular routers.
That is, the route goes first then the handler. Well, Go will slot the return values of a function into the arguments of another if they are an exact match. So, if Pocket provides a function that returns (string, func(http.ResponseWriter, *http.Request)) then Pocket can have access to the exact route declaration that is passed to Gorilla! Neat!
Where ArticlesCategoryHandler is a function that has all the magical benefits of Pocket!
So, what would pocket.HandlerGorilla do? It would be something along these lines:
funcHandlerGorilla(pathstring, finterface{}) (
string,
func(http.ResponseWriter, *http.Request),
) {
handler:=GenerateHandler(f)
// parse `path`// extract route variables that Gorilla will process - borrow Gorilla code?// match these route variables with props in handler.propsT/Vreturnpath, handlerFunc.Execute
}
And on the user side, it would look something like this:
r.HandleFunc(pocket.HandlerGorilla(
"/articles/{category}/{sort:(?:asc|desc|new)}",
func(propsstruct{
Categorystring`route:"category"`SortSortDir`route:"sort"`
}) pocket.Responder {
// perform some business logic with a database using propsresponse, err:=getData(props.Category, props.Sort)
iferr!=nil {
returnpocket.ErrInternalServerError(err)
}
// response is some type that satisfies pocket.Responderreturnresponse
})
))
(Rough concept, stuff might change)
Here, the props type specifies route tags which map to the {} variables in the route.
The text was updated successfully, but these errors were encountered:
One of the neat things Rocket.rs does is use function attributes to both declare the route that will bind to a function and specify the variables within a route. See an example of that here: https://rocket.rs/v0.4/guide/requests/#dynamic-paths
This is unfortunately not possible to carbon-copy due to Go's simplicity and minimalism. Also, routing/multiplexing isn't the goal of this library because there are plenty of great libraries for these tasks out there already!
I can however imagine building integrations for popular routers.
Gorilla's Mux library registers routes like this:
That is, the route goes first then the handler. Well, Go will slot the return values of a function into the arguments of another if they are an exact match. So, if Pocket provides a function that returns
(string, func(http.ResponseWriter, *http.Request))
then Pocket can have access to the exact route declaration that is passed to Gorilla! Neat!It would look something like this:
Where
ArticlesCategoryHandler
is a function that has all the magical benefits of Pocket!So, what would
pocket.HandlerGorilla
do? It would be something along these lines:And on the user side, it would look something like this:
(Rough concept, stuff might change)
Here, the props type specifies
route
tags which map to the{}
variables in the route.The text was updated successfully, but these errors were encountered: