Skip to content

Instantly share code, notes, and snippets.

@yukpiz
Last active November 24, 2016 06:30
Show Gist options
  • Save yukpiz/414d43a5d3247fc09f0fa8b8f327aa94 to your computer and use it in GitHub Desktop.
Save yukpiz/414d43a5d3247fc09f0fa8b8f327aa94 to your computer and use it in GitHub Desktop.
none

Getting Started for Revel

Installing go-lang.

$ wget https://storage.googleapis.com/golang/go1.7.3.linux-amd64.tar.gz
$ tar -C ~/.go zxvf go1.7.3.linux-amd64.tar.gz
$ vim ~/.bashrc
+ export GOROOT="$HOME/.go/go"
+ export GOPATH="$HOME/.go/extend"
+ export PATH="$GOROOT/bin:$GOPATH/bin:$PATH"

$ source ~/.bashrc

$GOROOTはGo本体の配置場所
$GOPATHはサードパーティ製のパッケージを配置する場所
go getした時のソースやgo installした時のバイナリが置かれる場所
Go本体はバージョンアップで古いGoを消すはずなので、
$GOPATH$GOROOTは分けた方が良い気がしてる

Installing Revel and command-line tools.

$ go get github.com/revel/revel
$ go get github.com/revel/cmd/revel
$ 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
    version     displays the Revel Framework and Go version

Use "revel help [command]" for more information.

Quick start.

$ mkdir -p $GOPATH/src/github.com/user
$ revel new github.com/user/appname
~
~ revel! http://revel.github.io
~
Your application is ready:
   /home/user/.go/extend/src/github.com/user/appname

You can run it with:
   revel run github.com/user/appname

$ revel run github.com/user/appname
~
~ revel! http://revel.github.io
~
INFO  2016/11/08 13:19:56 revel.go:365: Loaded module static
INFO  2016/11/08 13:19:56 revel.go:365: Loaded module testrunner
INFO  2016/11/08 13:19:56 revel.go:230: Initialized Revel v0.13.1 (2016-06-06) for >= go1.4
INFO  2016/11/08 13:19:56 run.go:57: Running appname (github.com/user/appname) in dev mode
INFO  2016/11/08 13:19:56 harness.go:170: Listening on :9000

How to deployment!!

$ revel build github.com/user/appname appname
$ cd appname
$ ./run.sh

//RubyのPassenger的なのは不要
//nginxで80->9000にマップしてscreenで走らせておくと良いかも

Revel commands.

Running application in development mode.

$ revel run github.com/user/appname

Running test.

$ revel test github.com/user/appname

Build and run the application.

$ revel build github.com/user/appname deploypath
$ cd deploypath
$ ./run.sh

Add new controller and view.

$ vim app/controller/menu.go
+ package controllers
+ import "github.com/revel/revel"
+ type Menu struct {
+     *revel.Controller
+ }
+ func (c Menu) Index() revel.Result {
+     return c.Render()
+ }

$ vim conf/routes
+ GET /menu Menu.Index

$ vim app/views/Menu/Index.html
+ <h1>Hello Revel!</h1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment