Echo
高性能,极简主义的Go Web框架
官方网站
项目地址
快速开始
Echo建议的使用方式是Gomod,因此我们需要把项目建立在$GOPATH
之外
例子:简单的Echo服务
package main
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func main() {
// Echo instance
e := echo.New()
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
// Routes
e.GET("/", hello)
// Start server
e.Logger.Fatal(e.Start("localhost:8080"))
}
// Handler
func hello(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
}
执行go run main.go
将依赖包下载到本地并运行服务
服务端输出
____ __
/ __/___/ / ___
/ _// __/ _ \/ _ \
/___/\__/_//_/\___/ v4.1.5
High performance, minimalist Go web framework
https://echo.labstack.com
____________________________________O/_______
O\
⇨ http server started on 127.0.0.1:8080
开启一个新的控制台执行curl 127.0.0.1:8080
客户端输出
Hello, World!
服务端输出
{"time":"2019-06-25T14:18:21.7213805+08:00","id":"","remote_ip":"127.0.0.1","host":"127.0.0.1:8080","method":"GET","uri":"/","user_agent":"curl/7.65.1","status":200,"error":"","latency":0,"latency_human":"0s","bytes_in":0,"bytes_out":13}
最后更新于