フレームワークを理解するのは難しいけど
とりあえず動かしてみよう。動かしていきながら理解できるかも…
準備
環境設定
mkdir ~/gocode export GOPATH=~/gocode echo export GOPATH=$GOPATH >> ~/.bash_profile
インストール
go get github.com/revel/revel go get github.com/revel/cmd/revel
※なにも出ないけど大丈夫みたいです
PATH設定
export PATH="$PATH:$GOPATH/bin" echo 'export PATH="$PATH:$GOPATH/bin"' >> ~/.bash_profile
コマンド確認
$ revel help ~ ~ revel! http://revel.github.io ~ usage: revel command [arguments] The commands are: new create a skeleton Revel application run run a Revel application build build a Revel application (e.g. for deployment) package package a Revel application (e.g. for deployment) clean clean a Revel application's temp files test run all tests from the command-line Use "revel help [command]" for more information. $
アプリ作成
revel newコマンドで作成
$ revel new sample1 ~ ~ revel! http://revel.github.io ~ Your application is ready: /home/vagrant/gocode/src/sample1 You can run it with: revel run sample1 $
revel runで起動
$ revel run sample1 ~ ~ revel! http://revel.github.io ~ INFO 2014/11/03 09:58:20 revel.go:326: Loaded module testrunner INFO 2014/11/03 09:58:20 revel.go:326: Loaded module static INFO 2014/11/03 09:58:20 run.go:57: Running sample1 (sample1) in dev mode INFO 2014/11/03 09:58:20 harness.go:165: Listening on :9000
シンプルな画面です
ディレクトリ構成
. ├── app │ ├── controllers │ │ └── app.go │ ├── init.go │ ├── routes │ │ └── routes.go │ ├── tmp │ │ └── main.go │ └── views │ ├── App │ │ └── Index.html │ ├── debug.html │ ├── errors │ │ ├── 404.html │ │ └── 500.html │ ├── flash.html │ ├── footer.html │ └── header.html ├── conf │ ├── app.conf │ └── routes ├── messages │ └── sample.en ├── public │ ├── css │ │ └── bootstrap.css │ ├── img │ │ ├── favicon.png │ │ ├── glyphicons-halflings.png │ │ └── glyphicons-halflings-white.png │ └── js │ └── jquery-1.9.1.min.js ├── README.md └── tests └── apptest.go
今回はここまで、ページ制御やコントローラーなどの動作はまた今度
問題
hg?
$ go get github.com/revel/revel go: missing Mercurial command. See http://golang.org/s/gogetcmd package github.com/revel/revel imports code.google.com/p/go.net/websocket: exec: "hg": executable file not found in $PATH $
↓
sudo yum install hg
GOPATH
gocodeは変えた場合
export GOPATH=/vagrant/golang/gocode export PATH="$PATH:$GOPATH/bin"
として
go get github.com/revel/revel go get github.com/revel/cmd/revel
としてアプリを作成すると
$ revel new sample2 ~ ~ revel! http://revel.github.io ~ Your application is ready: /vagrant/golang/gocode/src/sample2 You can run it with: revel run sample2 $