- gin
package main: import ( "fmt"; "net/http"; "github.com/gin-gonic/gin"; ) ; func main() { r := gin.Default(); r.GET("/", func(c *gin.Context) { fmt.Println("------ welcome to gin ------"); // --- string --- // c.String(http.StatusOK, "Hello World"); // --- json --- c.JSON(http.StatusOK, gin.H{ "message": "Hello World" }); }); r.Run(":3001"); }Copy the code
- fiber
package main; import ( "fmt"; "github.com/gofiber/fiber/v2"; ) ; func main() { app := fiber.New(); app.Get("/", func(c *fiber.Ctx) error { fmt.Println("------ welcome to fiber ------"); // --- string --- // return c.SendString("Hello World"); // --- json --- return c.JSON(fiber.Map{ "message": "Hello World", }); }); }Copy the code