LoginSignup
18
13

More than 5 years have passed since last update.

echoのv3にアップデートした時に修正した箇所

Posted at

echoのv3にアップデートした時に修正した箇所

Request, Response

net/httpとfasthttpの両対応のための抽象化がなくなったのでシンプルになった。

http.ResponseWriter

echo.Contextからhttp.ResponseWriterを取り出す方法。

// 旧
w := c.Response().(*standard.Response).ResponseWriter

// 新
w := c.Response()

http.Request

echo.Contextからhttp.ResponseWriterを取り出す方法。

// 旧
r := c.Request().(*standard.Response).Request

// 新
r := c.Request()

Query

// 旧
values := c.Request().URL().QueryParams()

// 新
values := c.Request().URL.Query()

RequestURI

// 旧
values := c.Request().URI()

// 新
values := c.Request().RequestURI

パス * の取得

ルーティングで "/foo/*" とした場合のパスパラメータの取得。

// 旧
c.P(0)

// 新
c.Param("*")

ServeContent

無くなったので、http.ServeContentを使う。

// 旧
err := c.ServeContent(fp, fi.Name(), fi.ModTime())

// 新
http.ServeContent(c.Response(), c.Request(), fi.Name(), fi.ModTime(), fp)

Start

// 旧
err := e.Run(standard.New(addr))

// 新
err := e.Start(addr)

Stop

Shutdownでタイムアウトを設定できるようになった。

// 旧
e.Stop()

// 新
e.Shutdown(time.Second * 3)
18
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
13