Migration
Migrate from Gin, Echo, or http.ServeMux to Rivaas Router.
2 minute read
This guide helps you migrate from other popular Go routers.
Route Registration
gin := gin.Default()
gin.GET("/users/:id", getUserHandler)
gin.POST("/users", createUserHandler)
e := echo.New()
e.GET("/users/:id", getUserHandler)
e.POST("/users", createUserHandler)
mux := http.NewServeMux()
mux.HandleFunc("/users/", usersHandler)
mux.HandleFunc("/posts/", postsHandler)
r := router.MustNew()
r.GET("/users/:id", getUserHandler)
r.POST("/users", createUserHandler)
Context Usage
func ginHandler(c *gin.Context) {
id := c.Param("id")
c.JSON(200, gin.H{"user_id": id})
}
func echoHandler(c echo.Context) error {
id := c.Param("id")
return c.JSON(200, map[string]string{"user_id": id})
}
func usersHandler(w http.ResponseWriter, r *http.Request) {
path := strings.TrimPrefix(r.URL.Path, "/users/")
userID := strings.Split(path, "/")[0]
// Manual parameter extraction
}
func rivaasHandler(c *router.Context) {
id := c.Param("id")
c.JSON(200, map[string]string{"user_id": id})
}
Middleware
gin.Use(gin.Logger(), gin.Recovery())
e.Use(middleware.Logger())
e.Use(middleware.Recover())
// Manual middleware chaining
handler := Logger(Recovery(mux))
http.ListenAndServe(":8080", handler)
r.Use(Logger(), Recovery())
Key Differences
Response Methods
| Feature | Gin | Echo | Rivaas |
|---|---|---|---|
| JSON | c.JSON() | c.JSON() | c.JSON() |
| String | c.String() | c.String() | c.String() |
| HTML | c.HTML() | c.HTML() | c.HTML() |
| Pure JSON | ✅ | ❌ | ✅ |
| Secure JSON | ✅ | ❌ | ✅ |
| YAML | ✅ | ❌ | ✅ |
Request Binding
| Feature | Gin | Echo | Rivaas |
|---|---|---|---|
| Query binding | ✅ | ✅ | ✅ |
| JSON binding | ✅ | ✅ | ✅ |
| Form binding | ✅ | ✅ | ✅ |
| Maps (dot notation) | ❌ | ❌ | ✅ |
| Maps (bracket notation) | ❌ | ❌ | ✅ |
| Nested structs in query | ❌ | ❌ | ✅ |
| Enum validation | ❌ | ❌ | ✅ |
| Default values | ❌ | ❌ | ✅ |
Next Steps
- Basic Usage: Review basic usage guide
- Examples: See complete examples
- API Reference: Check API documentation
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.