httprouter-adapter
httprouter-adapter is an adapter designed to seamlessly integrate httprouter with qiwlar, a lightweight web framework for Go. Additionally, it provides a convenient decorator called Params()
to retrieve all path parameters.
Example Usage
Here's an example of how to use httprouter-adapter in your Go application:
// main.go
package main
import (
httprouteradapter "github.com/levnikort/httprouter-adapter"
"github.com/levnikort/qiwlar"
"net/http"
)
func main() {
http.ListenAndServe(
":8080",
qiwlar.New(
nil,
httprouteradapter.New(),
),
)
}
// app_controller.go
package auth
import (
"fmt"
d "github.com/levnikort/qiwlar/decorator"
hrd "github.com/levnikort/httprouter-adapter/decorator"
"github.com/levnikort/qiwlar"
"github.com/julienschmidt/httprouter"
)
type AppController struct {
qiwlar.Controller
}
func (ac *AppController) Inject() interface{} {
return func() {}
}
func (ac *AppController) Initialize() {
ac.Equip("auth")(
hrd.Params(),
d.Post("sign-in/:id"),
func(params httprouter.Params) string {
fmt.Println(b)
return "id - " + params.ByName("id")
},
)
}
In this example, we import httprouter-adapter and use it in conjunction with qiwlar to create a web server. The Params()
decorator is applied to a route, allowing you to easily access path parameters in your request handler.
By using httprouter-adapter, you can streamline the integration of httprouter with qiwlar in your Go web applications, making it easier to build robust and efficient RESTful APIs.