Skip to content

Instantly share code, notes, and snippets.

@ytkhs
Created July 3, 2016 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytkhs/b35ff9818b1df066af6e7e3ad1243aee to your computer and use it in GitHub Desktop.
Save ytkhs/b35ff9818b1df066af6e7e3ad1243aee to your computer and use it in GitHub Desktop.
Go製のフレームワークechoをHerokuで動かす ref: http://qiita.com/qube81/items/b89ec5e663be934dccf5
go get github.com/labstack/echo/...
cd $GOPATH/src/echoproject
export PORT=8080
go run main.go
# http://localhost:8080 に "Hello, World!"と表示されていればOK
# godepの取得
go get github.com/kr/godep
# 私の環境では以下も必要でした
go get golang.org/x/sys/unix
# 依存関係を保存します
godep save
echo "web: $(basename `pwd`)" > Procfile
$GOPATH/src/echoproject
├── Godeps
│   ├── Godeps.json
│   └── Readme
├── Procfile
├── main.go
└── vendor
├── github.com
│   ├── dgrijalva
│   │   └── jwt-go
│   ├── labstack
│   │   ├── echo
│   │   └── gommon
│   ├── mattn
│   │   ├── go-colorable
│   │   └── go-isatty
│   └── valyala
│   └── fasttemplate
└── golang.org
└── x
├── net
└── sys
git init
git add .
git commit -m "initial commit"
# heroku側にアプリを作ります
heroku create
git push heroku master
# ブラウザで開きます
heroku open
heroku logs --tail
> 2016-07-03T02:36:24.386962+00:00 heroku[slug-compiler]: Slug compilation started
> 2016-07-03T02:36:24.386967+00:00 heroku[slug-compiler]: Slug compilation finished
> 2016-07-03T02:36:24.858458+00:00 heroku[web.1]: Starting process with command `echoproject`
> 2016-07-03T02:36:28.518721+00:00 heroku[web.1]: State changed from starting to up
package main
import (
"net/http"
"os"
"github.com/labstack/echo"
"github.com/labstack/echo/engine/standard"
"github.com/labstack/echo/middleware"
)
func main() {
// Echo instance
e := echo.New()
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
// Route => handler
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!\n")
})
// Start server
// ポート番号は環境変数から取得
e.Run(standard.New(":" + os.Getenv("PORT")))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment