Hello World 示例

服务器

server.go

  1. package main
  2. import (
  3. "net/http"
  4. "github.com/labstack/echo"
  5. "github.com/labstack/echo/middleware"
  6. )
  7. func main() {
  8. // Echo instance
  9. e := echo.New()
  10. // Middleware
  11. e.Use(middleware.Logger())
  12. e.Use(middleware.Recover())
  13. // Route => handler
  14. e.GET("/", func(c echo.Context) error {
  15. return c.String(http.StatusOK, "Hello, World!\n")
  16. })
  17. // Start server
  18. e.Logger.Fatal(e.Start(":1323"))
  19. }