LoginSignup
1
0

More than 3 years have passed since last update.

Echo middleware 実行順

Posted at

概要

Echo の middleware の実行順が気になったので試した。

コード

func main() {
    e := echo.New()
    e.Use(middleware.Hoge()) // fmt.Println("Hoge")
    e.Use(middleware.Foo()) // fmt.Println("Foo")
    e.Use(middleware.Bar()) // fmt.Println("Bar")

    e.GET("/", func(c echo.Context) error {
        var err error
        defer func() {
            if err != nil {
                e.Logger.Errorf("%+v", err)
            }
        }()

        fmt.Println("Request recieved")
        return c.String(http.StatusOK, "Hello, World")
    })
    e.Logger.Fatal(e.Start(":8080"))
}

// 実行結果
// Hoge
// Foo
// Bar
// Request recieved

予想通り、 Use した順に実行された。
以上

1
0
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
1
0