Created
July 3, 2016 03:00
-
-
Save ytkhs/b35ff9818b1df066af6e7e3ad1243aee to your computer and use it in GitHub Desktop.
Go製のフレームワークechoをHerokuで動かす ref: http://qiita.com/qube81/items/b89ec5e663be934dccf5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
go get github.com/labstack/echo/... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd $GOPATH/src/echoproject | |
export PORT=8080 | |
go run main.go | |
# http://localhost:8080 に "Hello, World!"と表示されていればOK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# godepの取得 | |
go get github.com/kr/godep | |
# 私の環境では以下も必要でした | |
go get golang.org/x/sys/unix | |
# 依存関係を保存します | |
godep save |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "web: $(basename `pwd`)" > Procfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git init | |
git add . | |
git commit -m "initial commit" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# heroku側にアプリを作ります | |
heroku create | |
git push heroku master | |
# ブラウザで開きます | |
heroku open |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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