LoginSignup
1
1

More than 3 years have passed since last update.

Golang の echo を使う

Last updated at Posted at 2018-06-11

次のようなページを表示する例です。
echo_jun1101.png

こちらのページの通りに行いました。
echo

1) インストール

go get -u github.com/labstack/echo/...

次のようなフォルダーがホームの直下にできます。

$ tree -L 3 go
go
├── pkg
│   └── linux_amd64
│       └── github.com
└── src
    ├── github.com
    │   ├── dgrijalva
    │   ├── labstack
    │   ├── mattn
    │   └── valyala
    └── golang.org
        └── x

2) サーバーのコードを用意

メッセージを日本語にしてみました。

server.go
package main

import (
    "net/http"

    "github.com/labstack/echo"
)

func main() {
    e := echo.New()
    e.GET("/", func(c echo.Context) error {
        return c.String(http.StatusOK, "こんにちは!")
    })
    e.Logger.Fatal(e.Start(":1323"))
}

3) サーバーの起動

$ go run server.go 

   ____    __
  / __/___/ /  ___
 / _// __/ _ \/ _ \
/___/\__/_//_/\___/ v3.3.dev
High performance, minimalist Go web framework
https://echo.labstack.com
____________________________________O/_______
                                    O\
⇨ http server started on [::]:1323

ディフォールト で外部からアクセスが出来ます。

4) ブラウザーでアクセス
http://localhost:1323/

次のバージョンで確認しました。

$ go version
go version go1.13.6 linux/amd64
1
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
1
1