2
1

More than 3 years have passed since last update.

GoでEchoの導入

Posted at

Echo の詳細

Echoの公式ドキュメント

インストール

go get github.com/labstack/echo/{version}

実際に動かす

main.go
package main

import (
  "net/http"
  "github.com/labstack/echo"
  "github.com/labstack/echo/middleware"
)

func main() {
  // Echoインスタンス作成
  e := echo.New()

  // ミドルウェア
  e.Use(middleware.Logger())
  e.Use(middleware.Recover())

  // ルーティング
  e.GET("/hello", hello)

  // サーバー起動
  e.Logger.Fatal(e.Start(":1323"))
}

// handler
func hello(c echo.Context) error {
  return c.String(http.StatusOK, "Hello, World!")
}

実行する

$ go run main.go

http://localhost:1323/hello にアクセスします。

result.
Hello World

と表示されます。

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